Closed
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