Skip to content

Fix invalid escape sequence SyntaxWarning in channel.py's doctest - #45

Draft
giodefelice-agents wants to merge 1 commit into
mainfrom
claude/wizardly-hopper-4clyxx
Draft

giodefelice-agents wants to merge 1 commit into
mainfrom
claude/wizardly-hopper-4clyxx

Conversation

@giodefelice-agents

Copy link
Copy Markdown
Collaborator

Fixes #42.

The bug

optyx/channel.py's module docstring is not a raw string. Its GHZ dual-rail example has symbol="$\\mapsto$"; Python collapses \\ to a single backslash while parsing the docstring itself, so the doctest's actual source text ends up as symbol="$\mapsto$". When doctest re-compiles that extracted text as its own Python source, \m is not a recognised escape sequence — reported every test run as SyntaxWarning: invalid escape sequence '\m'.

The fix

Double the escape on that one line (\\\\mapsto in source) so the text doctest actually sees is symbol="$\\mapsto$" — a valid, correctly-interpreted escape, same intended LaTeX output. Left the module docstring non-raw rather than converting to r"""...""", since several other lines rely on \\ collapsing to a single backslash for doctest's own line-continuation syntax; a blanket raw conversion would break those.

Verification

  • pflake8 optyx/channel.py: clean
  • python -W error::SyntaxWarning -m pytest --doctest-modules optyx/channel.py: 4 passed, all with SyntaxWarning promoted to an error
  • Confirmed the same command fails with exactly the reported SyntaxError: invalid escape sequence '\m' on unmodified main, to make sure the fix is what closes it (and not, say, a pre-existing pass).

Generated by Claude Code

The module docstring is not raw, so \\mapsto collapses to \mapsto while
Python parses the docstring itself. Doctest then re-compiles that text
as its own Python source, where \m is not a recognised escape sequence
-- reported as SyntaxWarning: invalid escape sequence '\m' on every
test run. Double the escape on that one line so the text doctest sees
is a literal \\mapsto, which is valid.

Fixes #42.

TODO.md quotes the issue instead of a verbatim human prompt, per the
discopy#513/#514 precedent for self-contained bug+fix pairs.

---
_Generated by [Claude Code](https://claude.ai/code)_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SyntaxWarning: invalid escape sequence '\m' in the channel.py module doctest

2 participants