FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-156327: Fix asyncio.print_call_graph() reporting its own frame by deadlovelll · Pull Request #156329 · python/cpython · GitHub

/ cpython Public
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 2 additions & 1 deletion Lib/asyncio/graph.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,5 @@ def print_call_graph(
limit: int | None = None,
) -> None:
"""Print the async call graph for the current task or the provided Future."""
print(format_call_graph(future, depth=depth, limit=limit), file=file)
# gh-156327: print_call_graph() must not report its own frame
print(format_call_graph(future, depth=depth + 1, limit=limit), file=file)
10 changes: 9 additions & 1 deletion Lib/test/test_asyncio/test_graph.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def walk(s):
return ret

buf = io.StringIO()
asyncio.print_call_graph(fut, file=buf, depth=depth+1)
asyncio.print_call_graph(fut, file=buf, depth=depth)

stack = asyncio.capture_call_graph(fut, depth=depth)
return walk(stack), buf.getvalue()
Expand Down Expand Up @@ -422,6 +422,14 @@ def test_capture_call_graph_non_future(self):
with self.assertRaises(TypeError):
asyncio.capture_call_graph("not a future")

async def test_print_call_graph_innermost_frame(self):
# gh-156327: print_call_graph() must not report its own frame
buf = io.StringIO()
lineno = sys._getframe().f_lineno + 1
asyncio.print_call_graph(file=buf)
first_frame = buf.getvalue().splitlines()[2]
self.assertIn(f'File {__file__!r}, line {lineno},', first_frame)

async def test_capture_call_graph_no_current_task(self):
results = []

Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :func:`asyncio.print_call_graph` including its own frame in the printed
call stack.
Loading

Back | FazBrowse Home | New Git URL