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: [Python 3.8] Wrong location flagged as syntax error
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: iljah, lys.nikolaou, pablogsal, vstinner
Priority: normal Keywords:

Created on 2020-10-09 13:43 by iljah, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg378321 - (view) Author: (iljah) Date: 2020-10-09 13:43
File:
#! /usr/bin/env python3
with \
  open('file1', 'w') as file1,
  open('file2', 'w') as file2:

  print('ok')

gives error:
  File "./test.py", line 3
    open('file1', 'w') as file1,
                         ^
SyntaxError: invalid syntax

but adding \ after file1 fixes it:
  open('file1', 'w') as file1, \


Location flagged by syntax error (between as and file1) is not correct.
msg378322 - (view) Author: (iljah) Date: 2020-10-09 13:46
Python 3.8.5
msg378323 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-10-09 13:47
Python 3.9 parser seems to be more accurate. I don't think that it's worth it to attempt to enhance Python 3.8 error reporting, since Python 3.9 got a whole new parser.


@apu$ python3.8 x.py 
  File "x.py", line 4
    open('file1', 'w') as file1,
                         ^
SyntaxError: invalid syntax


$ python3.9 x.py 
  File "/home/vstinner/x.py", line 4
    open('file1', 'w') as file1,
                                ^
SyntaxError: invalid syntax
msg378918 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-10-19 02:10
Closing this as the new parser in Python3.9+ handles this correctly
History
Date User Action Args
2022-04-11 14:59:36adminsetgithub: 86148
2020-10-19 02:10:08pablogsalsetstatus: open -> closed
resolution: fixed
messages: + msg378918

stage: resolved
2020-10-09 13:47:25vstinnersetnosy: + pablogsal, vstinner, lys.nikolaou

messages: + msg378323
title: Wrong location flagged as syntax error -> [Python 3.8] Wrong location flagged as syntax error
2020-10-09 13:46:01iljahsetmessages: + msg378322
2020-10-09 13:43:54iljahcreate