This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: compile() passes rest of file as SyntaxError().text when file unreadable
Type: behavior Stage: resolved
Components: Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, lys.nikolaou, pablogsal
Priority: normal Keywords: 3.4regression, patch

Created on 2020-05-14 03:57 by gvanrossum, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 20090 merged pablogsal, 2020-05-14 16:50
Messages (2)
msg368815 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-05-14 03:57
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.
msg368865 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-05-14 20:11
New changeset bcc30360951a303aa72b0502b77aad2c5f09f30d by Pablo Galindo in branch 'master':
bpo-40619: Correctly handle error lines in programs without file mode (GH-20090)
https://github.com/python/cpython/commit/bcc30360951a303aa72b0502b77aad2c5f09f30d
History
Date User Action Args
2022-04-11 14:59:31adminsetgithub: 84799
2020-05-14 20:12:11pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-05-14 20:11:54pablogsalsetmessages: + msg368865
2020-05-14 16:50:10pablogsalsetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request19395
2020-05-14 03:57:45gvanrossumsetnosy: + lys.nikolaou, pablogsal
2020-05-14 03:57:30gvanrossumcreate