[New-bugs-announce] [issue46521] compile_command not raising syntax error when command ends with triple quotes

Tushar Sadhwani report at bugs.python.org
Tue Jan 25 10:09:36 EST 2022


New submission from Tushar Sadhwani <tushar.sadhwani000 at gmail.com>:

compile_command used to raise error for this until Python 3.9:

```
>>> import code
>>> code.compile_command("abc def '''")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.9/codeop.py", line 132, in compile_command
    return _maybe_compile(_compile, source, filename, symbol)
  File "/usr/lib/python3.9/codeop.py", line 106, in _maybe_compile
    raise err1
  File "/usr/lib/python3.9/codeop.py", line 93, in _maybe_compile
    code1 = compiler(source + "\n", filename, symbol)
  File "/usr/lib/python3.9/codeop.py", line 111, in _compile
    return compile(source, filename, symbol, PyCF_DONT_IMPLY_DEDENT)
  File "<input>", line 1
    abc def '''
        ^
SyntaxError: invalid syntax
```

But in Python 3.10.0 it no longer is an error:

```
>>> import code
>>> code.compile_command("abc def '''")
>>>
```

----------
components: Parser
messages: 411608
nosy: lys.nikolaou, pablogsal, tusharsadhwani
priority: normal
severity: normal
status: open
title: compile_command not raising syntax error when command ends with triple quotes
type: behavior
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46521>
_______________________________________


More information about the New-bugs-announce mailing list