Skip to content

Commit 4f81af6

Browse files
petercorkeclaude
andauthored
fix: make the OA and conjugation docstrings raw strings (#251)
Two docstrings containing LaTeX are not raw strings, so compiling the package gives `invalid escape sequence '\m'` SyntaxWarnings (visible on every import under Python 3.12 until the `.pyc` is cached, and in Pyodide, which has no cache). In `UnitQuaternion.OA` it is worse than a warning: `\t` (of `\times`) and `\v` (of `\vec`) are valid escapes, so the rendered docs contain a tab and a vertical tab instead of the symbols. That docstring was rewritten in #195 without the `r` prefix; the `conjugation` one predates it. Adds a test that compiles every module and fails on `SyntaxWarning`/`DeprecationWarning`, so a non-raw docstring with a backslash fails CI. Checked by compiling the whole package on 3.12: two warnings before (`baseposematrix.py:629`, `quaternion.py:1454`), none after; the new test fails on `master` and passes with the change. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 81071a3 commit 4f81af6

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎spatialmath/baseposematrix.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ def stack(self) -> NDArray:
618618
return np.dstack(self.data)
619619

620620
def conjugation(self, A: NDArray) -> NDArray:
621-
"""
621+
r"""
622622
Matrix conjugation
623623
624624
:param A: matrix to conjugate

‎spatialmath/quaternion.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ def RPY(
14831483

14841484
@classmethod
14851485
def OA(cls, o: ArrayLike3, a: ArrayLike3) -> UnitQuaternion:
1486-
"""
1486+
r"""
14871487
Construct a new unit quaternion from two vectors
14881488
14891489
:param o: 3-vector parallel to Y- axis

‎tests/test_source_warnings.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""Compiling the package must not raise SyntaxWarning or DeprecationWarning.
2+
3+
A non-raw docstring containing LaTeX such as ``\\mat`` or ``\\vec`` gives an
4+
"invalid escape sequence" warning, and ``\\t`` or ``\\v`` (as in ``\\times`` and
5+
``\\vec``) are valid escapes that silently put a tab or vertical tab into the
6+
documentation. Use ``r\"\"\"`` for docstrings that contain backslashes.
7+
"""
8+
9+
import pathlib
10+
import unittest
11+
import warnings
12+
13+
import spatialmath
14+
15+
16+
class TestSourceWarnings(unittest.TestCase):
17+
def test_package_compiles_without_warnings(self):
18+
root = pathlib.Path(spatialmath.__file__).parent
19+
problems = []
20+
for path in sorted(root.rglob("*.py")):
21+
with warnings.catch_warnings(record=True) as caught:
22+
warnings.simplefilter("always")
23+
compile(path.read_text(encoding="utf-8"), str(path), "exec")
24+
problems += [
25+
f"{path.relative_to(root)}:{w.lineno}: {w.message}"
26+
for w in caught
27+
if issubclass(w.category, (SyntaxWarning, DeprecationWarning))
28+
]
29+
self.assertEqual(problems, [])
30+
31+
32+
if __name__ == "__main__":
33+
unittest.main()

0 commit comments

Comments
 (0)