Fix invalid escape sequence SyntaxWarning in channel.py's doctest - #45
Draft
giodefelice-agents wants to merge 1 commit into
Draft
giodefelice-agents wants to merge 1 commit into
giodefelice-agents wants to merge 1 commit into
Conversation
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)_
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #42.
The bug
optyx/channel.py's module docstring is not a raw string. Its GHZ dual-rail example hassymbol="$\\mapsto$"; Python collapses\\to a single backslash while parsing the docstring itself, so the doctest's actual source text ends up assymbol="$\mapsto$". When doctest re-compiles that extracted text as its own Python source,\mis not a recognised escape sequence — reported every test run asSyntaxWarning: invalid escape sequence '\m'.The fix
Double the escape on that one line (
\\\\mapstoin source) so the text doctest actually sees issymbol="$\\mapsto$"— a valid, correctly-interpreted escape, same intended LaTeX output. Left the module docstring non-raw rather than converting tor"""...""", 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: cleanpython -W error::SyntaxWarning -m pytest --doctest-modules optyx/channel.py: 4 passed, all withSyntaxWarningpromoted to an errorSyntaxError: invalid escape sequence '\m'on unmodifiedmain, to make sure the fix is what closes it (and not, say, a pre-existing pass).Generated by Claude Code