From 0e19da019cf92e676004bf4f889de030d6045c87 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 11 May 2025 13:43:18 +0200 Subject: [PATCH 1/5] asyncio.graph: Replace TextIO annotation with io.Writer --- Lib/asyncio/graph.py | 4 ++-- .../Library/2025-05-11-13-50-44.gh-issue-133893.Cv9Yxs.rst | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2025-05-11-13-50-44.gh-issue-133893.Cv9Yxs.rst diff --git a/Lib/asyncio/graph.py b/Lib/asyncio/graph.py index d8df7c9919abbf..cb601b477181ad 100644 --- a/Lib/asyncio/graph.py +++ b/Lib/asyncio/graph.py @@ -17,7 +17,7 @@ ) if False: # for type checkers - from typing import TextIO + from io import Writer # Sadly, we can't re-use the traceback module's datastructures as those # are tailored for error reporting, whereas we need to represent an @@ -270,7 +270,7 @@ def print_call_graph( future: futures.Future | None = None, /, *, - file: TextIO | None = None, + file: Writer[str] | None = None, depth: int = 1, limit: int | None = None, ) -> None: diff --git a/Misc/NEWS.d/next/Library/2025-05-11-13-50-44.gh-issue-133893.Cv9Yxs.rst b/Misc/NEWS.d/next/Library/2025-05-11-13-50-44.gh-issue-133893.Cv9Yxs.rst new file mode 100644 index 00000000000000..b97406cbfafd25 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-05-11-13-50-44.gh-issue-133893.Cv9Yxs.rst @@ -0,0 +1,3 @@ +Use protocol :class:`io.Writer` as annotation for +:func:`asyncio.graph.format_call_graph()`'s ``file`` argument instead of +:class:`typing.TextIO`. From 0410644e44b2634c39cda93b8c594773410ce8f1 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 11 May 2025 13:53:31 +0200 Subject: [PATCH 2/5] Fix linter complaint --- .../next/Library/2025-05-11-13-50-44.gh-issue-133893.Cv9Yxs.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-05-11-13-50-44.gh-issue-133893.Cv9Yxs.rst b/Misc/NEWS.d/next/Library/2025-05-11-13-50-44.gh-issue-133893.Cv9Yxs.rst index b97406cbfafd25..df5955972dd9ce 100644 --- a/Misc/NEWS.d/next/Library/2025-05-11-13-50-44.gh-issue-133893.Cv9Yxs.rst +++ b/Misc/NEWS.d/next/Library/2025-05-11-13-50-44.gh-issue-133893.Cv9Yxs.rst @@ -1,3 +1,3 @@ Use protocol :class:`io.Writer` as annotation for -:func:`asyncio.graph.format_call_graph()`'s ``file`` argument instead of +:func:`asyncio.graph.format_call_graph`'s ``file`` parameter instead of :class:`typing.TextIO`. From e3a14e560c8b0b430909843ad0942f2f242437bc Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 11 May 2025 13:59:30 +0200 Subject: [PATCH 3/5] Fix func reference in NEWS --- .../next/Library/2025-05-11-13-50-44.gh-issue-133893.Cv9Yxs.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-05-11-13-50-44.gh-issue-133893.Cv9Yxs.rst b/Misc/NEWS.d/next/Library/2025-05-11-13-50-44.gh-issue-133893.Cv9Yxs.rst index df5955972dd9ce..f8de16d2d04653 100644 --- a/Misc/NEWS.d/next/Library/2025-05-11-13-50-44.gh-issue-133893.Cv9Yxs.rst +++ b/Misc/NEWS.d/next/Library/2025-05-11-13-50-44.gh-issue-133893.Cv9Yxs.rst @@ -1,3 +1,3 @@ Use protocol :class:`io.Writer` as annotation for -:func:`asyncio.graph.format_call_graph`'s ``file`` parameter instead of +:func:`asyncio.format_call_graph`'s ``file`` parameter instead of :class:`typing.TextIO`. From a6570d7bf21d8c17a1aef49807e17654361339ec Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 11 May 2025 15:00:19 +0200 Subject: [PATCH 4/5] Remove NEWS entry --- .../Library/2025-05-11-13-50-44.gh-issue-133893.Cv9Yxs.rst | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 Misc/NEWS.d/next/Library/2025-05-11-13-50-44.gh-issue-133893.Cv9Yxs.rst diff --git a/Misc/NEWS.d/next/Library/2025-05-11-13-50-44.gh-issue-133893.Cv9Yxs.rst b/Misc/NEWS.d/next/Library/2025-05-11-13-50-44.gh-issue-133893.Cv9Yxs.rst deleted file mode 100644 index f8de16d2d04653..00000000000000 --- a/Misc/NEWS.d/next/Library/2025-05-11-13-50-44.gh-issue-133893.Cv9Yxs.rst +++ /dev/null @@ -1,3 +0,0 @@ -Use protocol :class:`io.Writer` as annotation for -:func:`asyncio.format_call_graph`'s ``file`` parameter instead of -:class:`typing.TextIO`. From 6fcd632a37ba283b392c090716133beedba07ff3 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 11 May 2025 16:06:47 +0200 Subject: [PATCH 5/5] Unlazify --- Lib/asyncio/graph.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Lib/asyncio/graph.py b/Lib/asyncio/graph.py index cb601b477181ad..b5bfeb1630a159 100644 --- a/Lib/asyncio/graph.py +++ b/Lib/asyncio/graph.py @@ -1,6 +1,7 @@ """Introspection utils for tasks call graphs.""" import dataclasses +import io import sys import types @@ -16,9 +17,6 @@ 'FutureCallGraph', ) -if False: # for type checkers - from io import Writer - # Sadly, we can't re-use the traceback module's datastructures as those # are tailored for error reporting, whereas we need to represent an # async call graph. @@ -270,7 +268,7 @@ def print_call_graph( future: futures.Future | None = None, /, *, - file: Writer[str] | None = None, + file: io.Writer[str] | None = None, depth: int = 1, limit: int | None = None, ) -> None: