Skip to content

Commit 3b96cc9

Browse files
Fix: guard added to inspect.getframeinfo to prevent TypeError when lineno is None
1 parent 3706ef6 commit 3b96cc9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Lib/inspect.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,9 @@ def getframeinfo(frame, context=1):
15821582

15831583
lineno = positions[0]
15841584

1585+
if lineno is None:
1586+
lineno = 1
1587+
15851588
if not isframe(frame):
15861589
raise TypeError('{!r} is not a frame or traceback object'.format(frame))
15871590

Lib/test/test_inspect/test_inspect.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import unittest.mock
2929
import warnings
3030
import weakref
31+
import inspect
32+
import sys
3133

3234

3335
try:
@@ -6250,3 +6252,18 @@ def f():
62506252

62516253
if __name__ == "__main__":
62526254
unittest.main()
6255+
6256+
def test_getframeinfo_with_exceptiongroup():
6257+
code = """
6258+
try:
6259+
1/0
6260+
except* Exception:
6261+
raise
6262+
"""
6263+
try:
6264+
exec(code)
6265+
except:
6266+
tb = sys.exc_info()[2]
6267+
while tb:
6268+
info = inspect.getframeinfo(tb.tb_frame)
6269+
tb = tb.tb_next

0 commit comments

Comments
 (0)