fix(descriptors): silence SyntaxWarning '\d' in TextMatch docstring#1883
Open
jbbqqf wants to merge 1 commit into
Open
fix(descriptors): silence SyntaxWarning '\d' in TextMatch docstring#1883jbbqqf wants to merge 1 commit into
jbbqqf wants to merge 1 commit into
Conversation
The TextMatch class docstring contains an inline regex example
`r"\b\d{3}-\d{3}-\d{4}\b"`. The `r"..."` prefix only marks the *example*
literal as raw — the docstring itself is a plain string, so Python 3.12+
parses `\b` and `\d` inside it and emits
`SyntaxWarning: invalid escape sequence '\d'` on every import.
Mark the docstring itself raw (`r""" ... """`). The rendered help text is
unchanged and the example regex still displays the same way.
Add a regression test that compiles the module under
`warnings.simplefilter("error", SyntaxWarning)` so this can't silently
regress on a future docstring edit.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Why
Importing
evidentlyon Python 3.12+ emits:The line in question lives inside the
TextMatchclass docstring. Ther"..."prefix only marks the example literal as raw — the docstringitself is a plain string, so Python parses every
\band\din it andraises a
SyntaxWarning. The warning is harmless at runtime but noisy inuser notebooks and shows up in CI logs of any downstream project that
imports evidently.
Fix
Mark the docstring itself raw (
r""" ... """). The rendered docstring isunchanged (verified via
TextMatch.__doc__) and the regex example stilldisplays the same way.
A small regression test (
test_text_match_module_compiles_without_syntax_warning)compiles
text_match.pyunderwarnings.simplefilter("error", SyntaxWarning)so this can't silently regress on a future docstring edit. The test
relies on
py_compile.compile(..., doraise=True), which converts theSyntaxWarning into a
PyCompileError— that way it works even when themodule is already imported (and therefore cached) elsewhere in the
process, which is the failure mode when running with the test suite's
shared
conftestimport.Reproduce BEFORE/AFTER yourself (copy-paste)
What I ran locally
Failing output before the fix (verbatim):
Edge cases
TextMatch.__doc__first 200 chars identical pre/postsrc/py_compilewalk ofsrc/evidently/**/*.pyflags only this one sitepy_compile.compile(..., doraise=True)instead of relying on importDisclosure: I drafted this PR with help from Claude Code while triaging
older issues. The reproduction, fix, and test runs above were executed
locally; outputs are copied verbatim.