← 返回首页
codeop: inconsistent handling of invalid escapes · Issue #96052 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

codeop: inconsistent handling of invalid escapes #96052

New issue
New issue

Description

Bug report

It seems like the codeop module is inconsistent with regards to handling of invalid escapes. For example, '\(' is accepted at the top level, but apparently not within indented blocks.

Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import codeop >>> codeop.compile_command("'\('") <code object <module> at 0x00000244A5BE6290, file "<input>", line 1> >>> codeop.compile_command("while False:\n\t'\('") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\kevin\AppData\Local\Programs\Python\Python310\lib\codeop.py", line 107, in compile_command return _maybe_compile(_compile, source, filename, symbol) File "C:\Users\kevin\AppData\Local\Programs\Python\Python310\lib\codeop.py", line 70, in _maybe_compile compiler(source + "\n", filename, symbol) File "C:\Users\kevin\AppData\Local\Programs\Python\Python310\lib\codeop.py", line 86, in _compile return compile(source, filename, symbol, PyCF_DONT_IMPLY_DEDENT | PyCF_ALLOW_INCOMPLETE_INPUT) File "<input>", line 2 '\(' ^^^^ SyntaxError: invalid escape sequence '\('

This can also be seen when submitting code via IDLE; e.g.

However, such code is accepted by a "plain" Python terminal:

Given the discrepancy, it seems like invalid escapes should perhaps be accepted by codeop here?

Your environment

Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32

Metadata

Metadata

Labels

type-bugAn unexpected behavior, bug, or error

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

  • Open in GitHub Copilot app

Footer

© 2026 GitHub, Inc.