Skip to content

lexer handles raw string escapes differently than documentation #121014

@anabelle2001

Description

@anabelle2001

Bug report

Bug description:

According to the docs,

Both string and bytes literals may optionally be prefixed with a letter 'r' or 'R'; such strings are called raw strings and treat backslashes as literal characters1

This does not hold during the lexing stage, where backslashes in raw strings always escape quotation marks:

print(r'\') # Causes SyntaxError, should print a single backslash
print(r'\'') # Prints `\'`, should give a syntax error

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Footnotes

  1. https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals,

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions