Skip to content
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

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

Closed
tkren mannequin opened this issue Jan 17, 2019 · 3 comments
Closed

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

tkren mannequin opened this issue Jan 17, 2019 · 3 comments
Labels
3.12 bugs and security fixes stdlib Python modules in the Lib dir topic-asyncio type-feature A feature request or enhancement

Comments

@tkren
Copy link
Mannequin

tkren mannequin commented Jan 17, 2019

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

    @tkren
    Copy link
    Mannequin Author

    tkren mannequin commented Jan 17, 2019

    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)
    {}

    @tkren tkren mannequin added 3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Jan 17, 2019
    @tirkarthi
    Copy link
    Member

    see also msg300475

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @kumaraditya303 kumaraditya303 added 3.12 bugs and security fixes and removed 3.8 only security fixes labels Mar 5, 2023
    @kumaraditya303 kumaraditya303 self-assigned this Mar 5, 2023
    @kumaraditya303 kumaraditya303 removed their assignment Mar 5, 2023
    @kumaraditya303
    Copy link
    Contributor

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

    miss-islington pushed a commit that referenced this issue Mar 11, 2023
    …sockets (GH-102605)
    
    Skip `TestGetAsyncGenState` and restoring of the default event loop policy in `test_inspect` if platform lacks working socket support.
    
    Fixes #11590
    
    Automerge-Triggered-By: GH:kumaraditya303
    iritkatriel pushed a commit to iritkatriel/cpython that referenced this issue Mar 12, 2023
    iritkatriel pushed a commit to iritkatriel/cpython that referenced this issue Mar 12, 2023
    …rking sockets (pythonGH-102605)
    
    Skip `TestGetAsyncGenState` and restoring of the default event loop policy in `test_inspect` if platform lacks working socket support.
    
    Fixes python#11590
    
    Automerge-Triggered-By: GH:kumaraditya303
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.12 bugs and security fixes stdlib Python modules in the Lib dir topic-asyncio type-feature A feature request or enhancement
    Projects
    Status: Done
    Development

    No branches or pull requests

    2 participants