Skip to content
3 changes: 3 additions & 0 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,9 @@ def getframeinfo(frame, context=1):

lineno = positions[0]

if lineno is None:
lineno = 1
Comment on lines +1585 to +1586
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? it might happen that lineno is None and should remains so.


if not isframe(frame):
raise TypeError('{!r} is not a frame or traceback object'.format(frame))

Expand Down
17 changes: 17 additions & 0 deletions Lib/test/test_inspect/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import unittest.mock
import warnings
import weakref
import inspect
import sys


try:
Expand Down Expand Up @@ -6250,3 +6252,18 @@ def f():

if __name__ == "__main__":
unittest.main()

def test_getframeinfo_with_exceptiongroup():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is not a test, it should be failing without the patch.

code = """
try:
1/0
except* Exception:
raise
"""
try:
exec(code)
except:
tb = sys.exc_info()[2]
while tb:
info = inspect.getframeinfo(tb.tb_frame)
tb = tb.tb_next
Loading