Skip to content

Fix Python 3.12+ SyntaxWarning: invalid escape sequence in token regexes - #55

Open
MBK-fr wants to merge 1 commit into
hisxo:masterfrom
MBK-fr:fix/py312-invalid-escape
Open

MBK-fr wants to merge 1 commit into
hisxo:masterfrom
MBK-fr:fix/py312-invalid-escape

Conversation

@MBK-fr

@MBK-fr MBK-fr commented Sep 9, 2026

Copy link
Copy Markdown

What

Several detection patterns in tokens.py (e.g. CLEAN_TOKEN_STEP1, GOOGLE_SECRET, TWILIO_AUTH) are plain non raw strings containing sequences like \=, \<, \>, \W and \s.

Why

On Python 3.12+ each of these emits SyntaxWarning: invalid escape sequence when gitGraber is imported, and CPython has scheduled them to become a SyntaxError in a future release.

Fix

Only the backslashes that form an invalid escape are doubled. Because an unrecognized escape currently passes the backslash through unchanged, doubling yields the exact same string value, so every compiled regex is byte for byte identical and detection behaviour is unchanged.

Validation: string-constant multiset identical before/after, and python3 -W error::SyntaxWarning -m py_compile tokens.py is clean.

….12+)

Several detection patterns in tokens.py are plain (non-raw) strings that
contain sequences such as \=, \<, \>, \W and \s. On Python 3.12+ these
emit SyntaxWarning: invalid escape sequence and are scheduled to become a
SyntaxError in a future release.

Only the backslashes that form an invalid escape are doubled, which leaves
every regex value (and therefore the matching behaviour) exactly the same
while removing the warnings.
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.

1 participant