ruff W605: fix changes program behavior
Hypothesis Nemotron 3 Super predicted to fire fired 1×
int/float/bool coercion, Decimal, division and rounding
Program
Output
(no stdout) /w/prog.py:1: SyntaxWarning: invalid escape sequence '\.'
(no stdout)
- fired
- 1 before · 0 after
- runs
- each version twice, same file name, no network
Judge Nemotron 3 Ultra advisory intended-change · low
The rule rewrites an invalid escape sequence '\.' to a raw string r'\.' to eliminate the SyntaxWarning, which is exactly the documented purpose. The stderr difference shows the deprecation warning disappearing, confirming the fix works as intended.
Explanation Nemotron 3 Super unverified
The original string literal `'\.'` contains an invalid escape sequence `\.` which Python treats as a literal backslash followed by a dot, but emits a SyntaxWarning because it’s not a recognized escape; the raw string `r'\.'` explicitly treats the backslash as a literal character without interpretation, so while both evaluate to the same two-character string (`\` then `.`), the original triggered a warning during compilation due to the invalid escape, whereas the raw string suppresses it—changing the program’s observable behavior (the warning output) even though the runtime value is identical. Thus, the fix alters semantics by removing a side effect (the warning).
Reproduce
- file
prog.py(the before program)- minimized program
- r1-p006.py
- evidence sheet
- r1-p006.md
- regression fixture
- r1-p006.py the minimized program with a header stating the observed change, for the tool's test suite
python3 prog.py ruff check --preview --isolated --select W605 --fix prog.py python3 prog.py
Upstream search GitHub issues Tavily Nemotron 3 Super + Ultra
W605 fix · W605 invalid escape sequence · backslash dot literal warning · raw string prefix recommendation
- related astral-sh/ruff/issues/11491 same rule W605 but different construct (f-string vs plain string)
- related astral-sh/ruff/issues/19655 W605 fix interaction with ISC002, same rule but different cause
- duplicate astral-sh/ruff/issues/11461 same rule W605, same fix (raw string), same defect class (invalid escape sequence in plain string)
- related astral-sh/ruff/issues/10434 W605 panic in f-string, same rule but different construct and symptom
- related astral-sh/ruff/issues/6987 W605 autofix error with ANN401, same rule but different trigger
- related astral-sh/ruff/issues/5061 feature request to use raw strings for W605, same fix strategy but not a defect report
- related astral-sh/ruff/issues/19543 W605 on byte strings, same rule but different string type
- related astral-sh/ruff/issues/12165 W605 panic on specific file, same rule but different symptom (panic vs wrong fix)
- related astral-sh/ruff/issues/474 original W605 implementation issue, same rule but not the same fix defect
Details
- program
- Numeric coercion and arithmetic
- hazard
- int/float/bool coercion, Decimal, division and rounding
- oracle
stderr before: /w/prog.py:1: SyntaxWarning: invalid escape sequence '\.' stderr after: (none)- run
- 2026-10-17T20-50-05-853Z-2tuo-ruff-W605
generated program (7 lines) and the fix's diff
--- orig.py 2026-10-17 16:50:21.403541462 -0400 +++ fixed.py 2026-10-17 16:50:21.613545540 -0400 @@ -1,5 +1,5 @@ from decimal import Decimal -s = '\.' +s = r'\.' print(bool(s)) print(int(s, 16) if all(c in '0123456789abcdefABCDEF' for c in s.replace('\\', '')) else 'NaN') d = Decimal('1.5')
rule documentation given to the models
# invalid-escape-sequence (W605) Derived from the **pycodestyle** linter. Fix is always available. ## What it does Checks for invalid escape sequences. ## Why is this bad? Invalid escape sequences are deprecated in Python 3.6. ## Example ```python regex = "\.png$" ``` Use instead: ```python regex = r"\.png$" ``` Or, if the string already contains a valid escape sequence: ```python value = "new line\nand invalid escape \_ here" ``` Use instead: ```python value = "new line\nand invalid escape \\_ here" ``` ## References - [Python documentation: String and Bytes literals](https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals)