Skip to content

inspect module does not implement introspection API for asynchronous generators #79940

Description

@tkren
mannequin
BPO 35759
Nosy @ncoghlan, @1st1, @tirkarthi, @tkren
PRs
  • gh-79940: add introspection API for asynchronous generators #11590
  • gh-79940: add introspection API for asynchronous generators #11590
  • Files
  • 0001-inspect-add-introspection-API-for-asynchronous-gener.patch: Initial patch for getasyncgenstate and getasyncgenlocals
  • 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:

    assignee = None
    closed_at = None
    created_at = <Date 2019-01-17.12:34:49.495>
    labels = ['3.8', 'type-feature', 'library']
    title = 'inspect module does not implement introspection API for asynchronous generators'
    updated_at = <Date 2019-01-17.14:15:35.489>
    user = 'https://github.com/tkren'

    bugs.python.org fields:

    activity = <Date 2019-01-17.14:15:35.489>
    actor = 'xtreak'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2019-01-17.12:34:49.495>
    creator = 'tkren'
    dependencies = []
    files = ['48066']
    hgrepos = []
    issue_num = 35759
    keywords = ['patch']
    message_count = 2.0
    messages = ['333861', '333870']
    nosy_count = 4.0
    nosy_names = ['ncoghlan', 'yselivanov', 'xtreak', 'tkren']
    pr_nums = ['11590', '11590']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue35759'
    versions = ['Python 3.8']

    Linked PRs

    Activity

    1. tkren commented on Jan 17, 2019

      tkrenmannequin
      MannequinAuthor

      The inspect module 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.getasyncgenstate and inspect.getasyncgenlocals (following inspect.isasyncgenfunction and inspect.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)
      {}
    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-featureA feature request or enhancement
      on Jan 17, 2019
    3. tirkarthi commented on Jan 17, 2019

      @tirkarthi
      Member

      see also msg300475

    4. transferred this issue fromon Apr 10, 2022
    5. added
      3.12only security fixes
      and removed on Mar 5, 2023
    6. removed their assignment
      on Mar 5, 2023
    7. kumaraditya303 commented on Mar 5, 2023

      @kumaraditya303
      Contributor

      I needed this today and was surprised that it wasn't implemented. I'll review the PR.

    8. added a commit that references this issue on Mar 11, 2023
    9. moved this from Todo to Done in asyncioon Mar 11, 2023
    10. added a commit that references this issue on Mar 11, 2023
    11. added 2 commits that reference this issue on Mar 12, 2023
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.12only security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-asynciotype-featureA feature request or enhancement

      Projects

      • Status
        Done

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions