[New-bugs-announce] [issue40619] compile() passes rest of file as SyntaxError().text when file unreadable

Guido van Rossum report at bugs.python.org
Wed May 13 23:57:30 EDT 2020


New submission from Guido van Rossum <guido at python.org>:

Example:

>>> compile("pass\n(1+)\npass", "<string>", "exec")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "", line 2
    (1+)
pass
       ^
SyntaxError: invalid syntax
>>> 

Note that the input is

pass
(1+)
pass

The second "pass" (and in fact the entire file) leaks into the SyntaxError object's text attribute.

This only happens when the file (here "<string>") cannot be read.

It's not specific to compile(), it seems fundamental in the C-level pegen API.

----------
keywords: 3.4regression
messages: 368815
nosy: gvanrossum
priority: normal
severity: normal
stage: needs patch
status: open
title: compile() passes rest of file as SyntaxError().text when file unreadable
type: behavior
versions: Python 3.9

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


More information about the New-bugs-announce mailing list