Repository navigation
inspect module does not implement introspection API for asynchronous generators #79940
Copy link
Copy link
Closed
Closed
Copy link
Labels
3.12only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotype-featureA feature request or enhancementA feature request or enhancement
Description
Activity
The
inspectmodule does not contain functions for determining the current state of asynchronous generators. That is, there is no introspection API for asynchronous generators that match the API for generators and coroutines: https://docs.python.org/3.8/library/inspect.html#current-state-of-generators-and-coroutines.I propose to add
inspect.getasyncgenstateandinspect.getasyncgenlocals(followinginspect.isasyncgenfunctionandinspect.isasyncgen).% ./python Python 3.8.0a0 (heads/fix-issue-getasyncgenstate:a24deae1e2, Jan 17 2019, 11:44:45) [GCC 6.3.0 20170516] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import inspect >>> async def agen(): ... x = 1 ... yield x ... x += 1 ... yield x ... >>> ag = agen() >>> inspect.getasyncgenstate(ag) 'AGEN_CREATED' >>> inspect.getasyncgenlocals(ag) {} >>> ag.__anext__().__next__() Traceback (most recent call last): File "<stdin>", line 1, in <module> StopIteration: 1 >>> inspect.getasyncgenstate(ag) 'AGEN_SUSPENDED' >>> inspect.getasyncgenlocals(ag) {'x': 1} >>> ag.__anext__().__next__() Traceback (most recent call last): File "<stdin>", line 1, in <module> StopIteration: 2 >>> inspect.getasyncgenstate(ag) 'AGEN_SUSPENDED' >>> inspect.getasyncgenlocals(ag) {'x': 2} >>> ag.aclose().send(None) Traceback (most recent call last): File "<stdin>", line 1, in <module> StopIteration >>> inspect.getasyncgenstate(ag) 'AGEN_CLOSED' >>> inspect.getasyncgenlocals(ag) {}
- added3.8 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
on Jan 17, 2019 see also msg300475
- added3.12only security fixesonly security fixesand removed3.8 (EOL)end of lifeend of life
on Mar 5, 2023 I needed this today and was surprised that it wasn't implemented. I'll review the PR.
Reacted by Thomas Krennwallner- added a commit that references this issue
on Mar 11, 2023 - added a commit that references this issue
on Mar 11, 2023
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotype-featureA feature request or enhancementA feature request or enhancement
Projects
- StatusShow more project fieldsDone
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
TestGetAsyncGenStateon wasm as it requires working sockets #102605