invalid-escape-sequence
What it does
Section titled “What it does”Reports a backslash in a string that is not raw and does not start an escape sequence ("\d", "\_"), also in the pieces of an f-string.
Why it matters
Section titled “Why it matters”The language keeps the backslash and the letter, so "\d" works today, but a later version can give the sequence a meaning, and newer interpreters already warn or reject it. It is also usually a regular expression or a Windows path where the author meant a different escape.
To fix, double the backslash ("\\d") or make the string raw (r"\d").
Example
Section titled “Example”x = "\d"y = r"\d"z = b"\d"f = f"\d {x} \w {x:\d} \{x}"g = "\u1234 \x41 \101 \n \\ \' \N{EM DASH}"h = "\8" "\_"i = """\d"""Configuration
Section titled “Configuration”python: lint: rules: invalid-escape-sequence: warn # off, warn (default), errorEnabled by the presets: python/ruff.
Suppress one line with sudsy-disable-next-line invalid-escape-sequence in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| ruff | W605 |
full |