◐ Shell
clean mode source ↗

Message 396456 - Python tracker

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