[issue29107] traceback module incorrectly formats args-less syntax errors

Irit Katriel report at bugs.python.org
Fri Sep 18 14:34:02 EDT 2020


Irit Katriel <iritkatriel at yahoo.com> added the comment:

As stated above, this has been fixed in python 3:

**********************************************************
C:\Users\User\src\cpython>type x.py
def f(x):
    global x

C:\Users\User\src\cpython>python.bat
Running Release|Win32 interpreter...
Python 3.10.0a0 (heads/bpo11414-dirty:6595cb0af4, Sep 18 2020, 19:01:13) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import traceback
>>> import x
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\User\src\cpython\x.py", line 2
    global x
    ^
SyntaxError: name 'x' is parameter and global
>>> try:
...     import x
... except:
...     traceback.print_exc()
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "C:\Users\User\src\cpython\x.py", line 2
    global x
    ^
SyntaxError: name 'x' is parameter and global
>>>


**********************************************************
>>> e = SyntaxError("some message", ("myfile.py", None, None, None))
>>> raise e
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SyntaxError: some message (myfile.py)
>>> try:
...     raise e
... except:
...     traceback.print_exc()
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "<stdin>", line 2, in <module>
  File "<stdin>", line 1, in <module>
  File "myfile.py", line None
SyntaxError: some message
**********************************************************

>>> e = SyntaxError("some message", ("myfile.py", 3, 10, "hello"))
>>> raise r
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'r' is not defined
>>> raise e
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "myfile.py", line 3
    hello
         ^
SyntaxError: some message
>>> try:
...     raise e
... except:
...     traceback.print_exc()
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "<stdin>", line 1, in <module>
  File "myfile.py", line 3
    hello
         ^
SyntaxError: some message

----------
nosy: +iritkatriel

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


More information about the Python-bugs-list mailing list