[New-bugs-announce] [issue36919] Exception form 'compile' reports a newline char not present in input

Pavel Koneski report at bugs.python.org
Tue May 14 16:28:37 EDT 2019


New submission from Pavel Koneski <pavel.koneski at gmail.com>:

Since Python 3.2, input in 'exec' mode  of 'compile' does not have to end in a newline anymore. However, it creates a surprising behavior when a 'SyntaxError' is reported:

>>> try: compile('try', '<string>', 'exec')
... except SyntaxError as ex: print(repr(ex))
... 
SyntaxError('invalid syntax', ('<string>', 1, 4, 'try\n'))

The 'text' field of the exception thrown contains an additional newline character that was not present in the input. Is it:

a. Proper Python language behavior?
b. CPython implementation artifact?
c. A bug?

In case of:

a. I will submit a patch to IronPython, which does not add an extra newline at the moment.
b. I can submit a patch to CPython to make StdLib tests implementation independent.
c. This inquiry can serve as a bug report.

----------
components: Interpreter Core
messages: 342515
nosy: BCSharp
priority: normal
severity: normal
status: open
title: Exception form 'compile' reports a newline char not present in input
type: behavior
versions: Python 3.5, Python 3.6, Python 3.7, Python 3.8

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


More information about the New-bugs-announce mailing list