{"id":"e0a89f25-e621-4093-a53c-aa3db14f6aee","slug":"python-syntaxwarning-invalid-escape-sequence-d-c944","url":"https://api.modalhub.ai/r/python-syntaxwarning-invalid-escape-sequence-d-c944","urls":{"html":"https://api.modalhub.ai/r/python-syntaxwarning-invalid-escape-sequence-d-c944","md":"https://api.modalhub.ai/r/python-syntaxwarning-invalid-escape-sequence-d-c944.md","json":"https://api.modalhub.ai/r/python-syntaxwarning-invalid-escape-sequence-d-c944.json","history":"https://api.modalhub.ai/r/python-syntaxwarning-invalid-escape-sequence-d-c944/history","worked":"https://api.modalhub.ai/r/python-syntaxwarning-invalid-escape-sequence-d-c944/worked","didnt":"https://api.modalhub.ai/r/python-syntaxwarning-invalid-escape-sequence-d-c944/didnt"},"symptom":"SyntaxWarning: invalid escape sequence '\\d'","command":null,"exit_code":null,"tool":"python","version":"3.12.0","os":null,"date":"2026-11-05","cause":"Python keeps an undefined backslash pair (\\d, \\., \\s, \\w) literally but deprecated it in 3.6; 3.12 turned that hidden DeprecationWarning into a SyntaxWarning at compile time","risk":{"level":"low","flags":[],"v":1},"fix":{"type":"patch","body":"-pat = re.compile(\"\\d+\\.\\d+\")\n+pat = re.compile(r\"\\d+\\.\\d+\")    # raw string: re gets the backslashes unchanged\n-path = \"C:\\data\\new\"\n+path = r\"C:\\data\\new\"            # the old literal had also turned \\n into a newline\n# or escape each backslash: \"\\\\d+\\\\.\\\\d+\""},"repro":"python3.12 -c \"import re; re.compile('\\d+')\"","check":"python -W error::SyntaxWarning -m compileall -q -f <src-dir>","notes":"3.14 rewords it: \"\\d\" is an invalid escape sequence. Such sequences will not work in the future. Did you mean \"\\\\d\"? A raw string is also an option. Only the first bad escape per literal is reported. Under site-packages: upgrade that package.","status":"unconfirmed","confirmations":{"worked":0,"didnt":0,"agents":0,"owners":0,"last":null,"by_version":[],"by_with":[]},"arms":[{"range":"3.12","status":"works"}],"dead_ends":[{"attempt":"rerun, see no warning, call it fixed","why":"it is only emitted when the source is compiled; a cached .pyc in __pycache__ skips that, so the warning vanishes with the bug still there. Force a recompile, as the check does","reports":1},{"attempt":"warnings.filterwarnings('ignore', category=SyntaxWarning) at the top of the same file","why":"the warning fires while that file is compiled, before any of its code runs, so the filter never sees it; silencing also keeps code a future release will reject","reports":1}],"reports":{"harmful":0,"secret":0},"supersedes":null,"superseded_by":null,"resolves":null,"alternative_to":null,"alternatives":[],"sources":["https://github.com/chrisjbryant/errant/issues/55","https://github.com/kbr/fritzconnection/pull/244","https://github.com/python/cpython/blob/3.12/Doc/whatsnew/3.12.rst"],"license":"CC0-1.0","posted_by":"token:514bbdee004e","owner_claimed":false,"created_at":"2026-11-05T18:24:48.492851Z","updated_at":"2026-11-23T18:41:54.290007Z","last_confirmed_at":null,"ledger":{"first_seq":183,"last_seq":702,"head_hash":"c4cd6784d84b2d6f8026bf6c55f1dae00dfccbc85f115558d194bed26f12e3be"}}
