# ruff W605: fix changes program behavior

Internal evidence sheet generated by fixhunt. Not an issue text. A human re-verifies, checks the duplicates
below, and writes the upstream report in their own words following the project's AI policy.

- Tool: ruff ruff 0.17.1
- Rule: W605 (tool labels the fix: unknown, this fix reported as safe)
- Oracle: fix-changes-behavior
- Judge (Nemotron 3 Ultra, advisory): intended-change, severity low. The rule rewrites an invalid escape sequence '\.' to a raw string r'\.' to eliminate the SyntaxWarning, which is the documented purpose of the fix. The program's behavior changes only by removing the deprecation warning, exactly as intended.
- Program: minimized from 10 to 1 lines

## Reproducer

```python
pattern = '\.'
```

## Commands

```sh
python3 prog.py
ruff check --preview --isolated --select W605 --fix prog.py
python3 prog.py
```

## Observed

```
stderr before: /w/prog.py:1: SyntaxWarning: invalid escape sequence '\.'
stderr after: (none)
```

## Diff applied by the fix

```diff
--- orig.py	2026-10-22 13:32:44.666301405 -0400
+++ fixed.py	2026-10-22 13:32:46.889338781 -0400
@@ -1 +1 @@
-pattern = '\.'
+pattern = r'\.'
```

## Why the rewrite is not equivalent (model draft, verify before use)

The original string literal `'\.'` contains an invalid backslash‑dot escape; Python emits a SyntaxWarning but still treats it as the two‑character string consisting of a backslash followed by a dot. Rewriting it as a raw string `r'\.'` removes the warning, yet the resulting value remains identical—a backslash and a dot—so the program’s observable behavior does not change; only the diagnostic message differs. Thus the fix is safe regarding semantics, though it alters the warning output.

## Upstream search

Queries: "W605 fix", "W605 regex pattern backslash dot", "invalid escape sequence warning fix", "raw string literal prefix addition"

- related: https://github.com/astral-sh/ruff/issues/11491
  Existing report is about W605 fix in f-strings, new finding is a plain string literal.
- duplicate: https://github.com/astral-sh/ruff/issues/11461
  Existing report 'W605 fix is unsafe' describes the same defect: autofix converts '\.' to raw string r'\.' which changes regex meaning.
- related: https://github.com/astral-sh/ruff/issues/10434
  W605 panic on f-string with backslashes, different construct (f-string vs plain string).
- related: https://github.com/astral-sh/ruff/issues/6987
  ANN401/W605 autofix error, but not the same raw-string behavior-change defect.
- related: https://github.com/astral-sh/ruff/issues/5061
  Feature request to use raw strings for W605 fix, which is what the new finding demonstrates going wrong.
- related: https://github.com/astral-sh/ruff/pull/5352
  PR implementing raw-string fix for W605, which introduced the defect in the new finding.

<details><summary>All hits</summary>

- [github, open] Wrong fix for W605 in f-strings — https://github.com/astral-sh/ruff/issues/11491
- [github, open] Implement remaining `pycodestyle` rules — https://github.com/astral-sh/ruff/issues/2402
- [github, open] Include some of the checks from flake8-literal — https://github.com/astral-sh/ruff/issues/8616
- [github, closed] unused-function-argument not silenced by prefixed underscore if variable name is "次" — https://github.com/astral-sh/ruff/issues/28721
- [github, open] Implement Pylint — https://github.com/astral-sh/ruff/issues/970
- [github, closed] ISC002 makes W605 unfixable on playground — https://github.com/astral-sh/ruff/issues/19655
- [github, closed] W605 fix is unsafe — https://github.com/astral-sh/ruff/issues/11461
- [github, closed] Ruff does not clean up unused import if it has same name like object attribute — https://github.com/astral-sh/ruff/issues/12775
- [github, closed] Pack of fuzzer Autofix/Infinite loop errors [2] — https://github.com/astral-sh/ruff/issues/8402
- [github, closed] Rule W605 cause panic — https://github.com/astral-sh/ruff/issues/10434
- [tavily] Rules ANN401,W605 cause autofix error · Issue #6987 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/6987
- [tavily] Change W605 autofix to use raw strings if possible · Issue #5061 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/5061
- [tavily] Format breaks f-string with literal strings inside (versions 0.3.0 and 0.3.1) · Issue #10273 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/10273
- [tavily] Should W605 flag certain byte string escapes? · Issue #19543 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/19543
- [tavily] Change W605 autofix to use raw strings if possible by hauntsaninja · Pull Request #5352 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/pull/5352
- [github, open] G004 fix can change behavior and introduce syntax errors — https://github.com/astral-sh/ruff/issues/20151
- [github, open] Unified command for linting and formatting — https://github.com/astral-sh/ruff/issues/8232
- [github, closed] [Linter panic] panicked at 'called `Option::unwrap()` in pycodestyle invalid_escape_sequence.rs — https://github.com/astral-sh/ruff/issues/9542
- [github, closed] In `ruff` 0.0.258 the `pydocstyle` rules are being enabled and can't be disabled with `[tool.ruff.pydocstyle]` defined.  — https://github.com/astral-sh/ruff/issues/3687
- [tavily] Validation for ruff config file · Issue #10487 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/10487
- [tavily] Get python version from environment · Issue #769 · astral-sh/ruff-vscode · GitHub — https://github.com/astral-sh/ruff-vscode/issues/769
- [github, open] Feature: Port Sonar's Python scanner checks — https://github.com/astral-sh/ruff/issues/4935
- [tavily] Raw strings break the FLY002 fix · Issue #21082 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/21082
- [tavily] UP032 fix misinterprets `\N` in a raw string as an escape sequence · Issue #22060 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/22060
- [tavily] Discrepancy between `format` and `check` for a long string literal · Issue #9926 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/9926

</details>
