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.

Author shreyanavigyan
Recipients Anthony Sottile, Mark.Shannon, domdfcoding, gvanrossum, pablogsal, shreyanavigyan, vstinner
Date 2021-06-24.07:03:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1624518224.15.0.424664610893.issue44297@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2021-06-24 07:03:44shreyanavigyansetrecipients: + shreyanavigyan, gvanrossum, vstinner, Mark.Shannon, Anthony Sottile, pablogsal, domdfcoding
2021-06-24 07:03:44shreyanavigyansetmessageid: <1624518224.15.0.424664610893.issue44297@roundup.psfhosted.org>
2021-06-24 07:03:44shreyanavigyanlinkissue44297 messages
2021-06-24 07:03:43shreyanavigyancreate