ruff W605: fix changes program behavior
Hypothesis Nemotron 3 Super predicted to fire fired 1×
If the string is adjacent to another string literal for concatenation (e.g., "a" "b"), and the fix is applied only to one part, the resulting concatenated string may have unintended backslash duplicat
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 the invalid escape sequence '\.' into a raw string r'\.' to eliminate the SyntaxWarning, which is exactly the documented purpose. The program's output changes because the warning disappears, demonstrating the rule did what it documents.
Explanation Nemotron 3 Super unverified
The original string literal `'\.'` contains an invalid escape sequence `\.` which Python treats as two characters: backslash followed by dot, while issuing a SyntaxWarning. After rewriting to `r'\.'`, it becomes a raw string where `\.` is interpreted literally as backslash-dot without warning. Although both evaluate to the same two-character string `'\\.'`, the change eliminates the SyntaxWarning that was present in the original program’s stderr output. Since the fix alters observable behavior—specifically, removing a diagnostic message—the transformation is not semantics-preserving under the criterion that includes all program outputs, including warnings. Thus, labeling the fix as "safe" is incorrect because it changes what the program emits during execution.
Reproduce
- file
prog.py(the before program)- minimized program
- r1-p001.py
- evidence sheet
- r1-p001.md
- regression fixture
- r1-p001.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 · invalid escape sequence dot · W605 raw string recommendation · backslash literal warning
- related astral-sh/ruff/issues/11491 Both involve W605 autofix changing behavior, but the existing report is about f-strings while the new finding is about implicit string concatenation.
- related astral-sh/ruff/issues/19655 Both involve W605 autofix issues, but the existing report is about interaction with ISC002 on multi-line strings, while the new finding is about implicit concatenation on a single line.
- duplicate astral-sh/ruff/issues/11461 The existing report is titled 'W605 fix is unsafe' and describes the autofix changing behavior by adding a raw prefix to a string with an invalid escape sequence, which is exactly the same defect on the same construct (implicit string concatenation with an invalid escape).
- related astral-sh/ruff/issues/10434 Both involve W605 causing issues with autofix, but the existing report is about a panic/crash on f-strings, while the new finding is about a silent behavior change on implicit concatenation.
- related astral-sh/ruff/issues/6987 Both involve W605 autofix errors, but the existing report mentions ANN401 and W605 causing autofix errors generally, not the specific behavior change on implicit concatenation.
- related astral-sh/ruff/issues/5061 This is a feature request to use raw strings for W605 fixes, which is what the autofix does in the new finding, but the request doesn't describe the behavior-change defect.
- related astral-sh/ruff/issues/20151 Both involve autofix changing behavior (G004 vs W605), but the existing report is about G004 on a different construct.
- related astral-sh/ruff/issues/20196 Both involve W605 and invalid escape sequences, but the existing report is about auditing CPython SyntaxWarning parity, not the autofix behavior change.
Details
- program
- String concatenation adjacency
- hazard
- If the string is adjacent to another string literal for concatenation (e.g., "a" "b"), and the fix is applied only to one part, the resulting concatenated string may have unintended backslash duplicat
- 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:20.020514587 -0400 +++ fixed.py 2026-10-17 16:50:20.224518552 -0400 @@ -1,4 +1,4 @@ -s = '\.' 'rest' +s = r'\.' 'rest' t = s print(repr(t)) if '__' in t:
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)