[issue44297] Frame with -1 line number

Shreyan Avigyan report at bugs.python.org
Thu Jun 24 03:03:44 EDT 2021


Shreyan Avigyan <shreyan.avigyan at gmail.com> added the comment:

Found the culprit - https://github.com/python/cpython/blob/769d7d0c66c5b86e2dd29b9ce67ac2daaab1bb38/Python/compile.c#L5268

Same goes for async with - https://github.com/python/cpython/blob/769d7d0c66c5b86e2dd29b9ce67ac2daaab1bb38/Python/compile.c#L5171
(Didn't test async with so I can be wrong there.)

Is this intentional? I removed these lines and the line number is coming correct. Can changing this affect other use cases?

Without the change:


Traceback (most recent call last):
  File "C:\Users\shrey\Desktop\line_negative_one.py", line 8, in <module>
    raise Exception("Normal Error")
Exception: Normal Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\shrey\Desktop\line_negative_one.py", line -1, in <module>
  File "C:\Users\shrey\Desktop\line_negative_one.py", line 5, in __exit__
    raise Exception("Frame is -1 if program is run from command line")
Exception: Frame is -1 if program is run from command line



With the change:



Traceback (most recent call last):
  File "C:\Users\shrey\Desktop\line_negative_one.py", line 8, in <module>
    raise Exception("Normal Error")
Exception: Normal Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\shrey\Desktop\line_negative_one.py", line 7, in <module>
    with A():
  File "C:\Users\shrey\Desktop\line_negative_one.py", line 5, in __exit__
    raise Exception("Frame is -1 if program is run from command line")
Exception: Frame is not -1 anymore if program is run from command line

----------

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


More information about the Python-bugs-list mailing list