fixhunt

ruff W605: fix changes program behavior

fix-changes-behaviorlabelled safeintended-change · lowduplicate
Findings / 2026-10-17T20-50-05-853Z-2tuo-ruff-W605 / r1-p006ruff 0.17.17 → 1 lines2026-10-17 20:50 UTC

Hypothesis Nemotron 3 Super predicted to fire fired 1×

int/float/bool coercion, Decimal, division and rounding

Program

before
1s = '\.'
after
1s = r'\.'

Output

stdout beforeexit 0
(no stdout)
/w/prog.py:1: SyntaxWarning: invalid escape sequence '\.'
stdout afterexit 0
(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

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
1from decimal import Decimal
2s = '\.'
3print(bool(s))
4print(int(s, 16) if all(c in '0123456789abcdefABCDEF' for c in s.replace('\\', '')) else 'NaN')
5d = Decimal('1.5')
6print(d / 2)
7print(round(2.5))
--- 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)