anomalous-backslash-in-string / W1401#

Message emitted:

Anomalous backslash in string: '%s'. String constant might be missing an r prefix.


Used when a backslash is in a literal string but not as an escape.

Problematic code:

string = "\z"  # [anomalous-backslash-in-string]

Correct code:

string = "\\z"

string = "\t"

string = r"\z"

Additional details:

\z is same as \\z because there's no escape sequence for z. But it is not clear for the reader of the code.

Related links:

Created by the string checker.