8000 GH-96092: restore frame height of traceback.walk_stack to that of pyt… by graingert · Pull Request #99015 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-96092: restore frame height of traceback.walk_stack to that of pyt… #99015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -2245,6 +2245,15 @@ def deeper():
s2 = deeper()
self.assertEqual(len(s2) - len(s1), 1)
self.assertEqual(s2[1:], s1)

def test_walk_stack_frame():
gen = traceback.walk_stack(None)
def deep():
def deeper():
return list(gen)[0][0]
return deeper()

self.assertIs(deep().f_code, deep.__code__)

def test_walk_tb(self):
try:
Expand Down
2 changes: 1 addition & 1 deletion Lib/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def walk_stack(f):
current stack is used. Usually used with StackSummary.extract.
"""
if f is None:
f = sys._getframe().f_back.f_back.f_back.f_back
f = sys._getframe().f_back.f_back
while f is not None:
yield f, f.f_lineno
f = f.f_back
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
restore frame height of :func:`traceback.walk_stack` to that of python 3.10
0