GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — asyncio.iscoroutinefunction(<async_generator>.asend) returns False · Issue #81371 · python/cpython

asyncio.iscoroutinefunction(<async_generator>.asend) returns False #81371

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
asyncio.iscoroutinefunction(<async_generator>.asend) returns False#81371
Copy link
Labels
topic-asynciotype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

RaduMateiLcraru
mannequin
opened on Jun 7, 2019
Issue body actions
BPO 37190
Nosy @asvetlov, @1st1

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-06-07.08:57:50.425>
labels = ['type-bug', '3.7', 'expert-asyncio']
title = 'asyncio.iscoroutinefunction(<async_generator>.asend) returns False'
updated_at = <Date 2019-06-07.08:57:50.425>
user = 'https://bugs.python.org/RaduMateiLcraru'

bugs.python.org fields:

activity = <Date 2019-06-07.08:57:50.425>
actor = 'Radu Matei L\xc4\x83craru'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['asyncio']
creation = <Date 2019-06-07.08:57:50.425>
creator = 'Radu Matei L\xc4\x83craru'
dependencies = []
files = []
hgrepos = []
issue_num = 37190
keywords = []
message_count = 1.0
messages = ['344910']
nosy_count = 3.0
nosy_names = ['asvetlov', 'yselivanov', 'Radu Matei L\xc4\x83craru']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue37190'
versions = ['Python 3.6', 'Python 3.7']

Linked PRs

  • gh-81371: implementing checking async generator methods #102129

Activity

  1. RaduMateiLcraru commented on Jun 7, 2019

    @RaduMateiLcraru
    RaduMateiLcrarumannequin
    on Jun 7, 2019
    MannequinAuthor
    More actions
    asyncio.iscoroutinefunction(<async_generator>.__anext__)
    asyncio.iscoroutinefunction(<async_generator>.asend)
    asyncio.iscoroutinefunction(<async_generator>.athrow)
    asyncio.iscoroutinefunction(<async_generator>.aclose)

    All of these return False, is this the intended behavior? Aren't all of these in fact coroutine functions?

  2. RaduMateiLcraru
    added
    3.7 (EOL)end of lifeend of life
    topic-asyncio
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Jun 7, 2019
  3. ezio-melotti
    transferred this issue fromon Apr 10, 2022
  4. ezio-melotti
    added this to asyncioon Jun 20, 2022
  5. ezio-melotti
    moved this to Todo in asyncioon Jul 17, 2022
  6. kumaraditya303 commented on Jul 17, 2022

    @kumaraditya303
    kumaraditya303
    on Jul 17, 2022
    Contributor
    More actions

    These functions are not coroutine functions but rather functions which return an awaitable object. You can use inspect.isawaitable on the result of asend to check if it is awaitable.

  7. kumaraditya303
    closed this as not plannedon Jul 17, 2022
  8. Repository owner moved this from Todo to Done in asyncioon Jul 17, 2022
  9. graingert commented on Jul 21, 2022

    @graingert
    graingert
    on Jul 21, 2022
    Contributor
    More actions

    @kumaraditya303 they are functions that return coroutines - otherwise they could not be used with asyncio.create_task(agen.asend())

    >>> import asyncio
    >>> async def async_generator(): yield
    ... 
    >>> asyncio.iscoroutine(async_generator().asend(None))
    True
    >>> 

    so I think this needs re-opening

  10. graingert
    reopened this on Jul 22, 2022
  11. Repository owner moved this from Done to In Progress in asyncioon Jul 22, 2022
  12. kumaraditya303 commented on Jul 22, 2022

    @kumaraditya303
    kumaraditya303
    on Jul 22, 2022
    Contributor
    More actions

    It is not a coroutine object but rather async_generator_asend object which has methods and some attributes of coroutine so behaves like it. iscoroutinefunction only works correctly for async def functions not native methods which returns an awaitable object hence I suggested to use inspect.isawaitable.

  13. kumaraditya303
    removed
    3.7 (EOL)end of lifeend of life
    on Jul 22, 2022
  14. graingert commented on Jul 23, 2022

    @graingert
    graingert
    on Jul 23, 2022
    Contributor
    More actions

    The bug here is with async_generator_asend/athrow
    quoting @njsmith here:

    Conceptually the asend and athrow methods on async generators are just regular async functions, and if they were implemented that way they'd automatically raise the same "forgot to await" warnings that all async functions get. But because they're implemented directly in C, they don't get that infrastructure "for free"; it has to be added manually, and it's one of those minor fiddly details that's easy to miss when you're implementing something complicated like this.

    now that inspect.is*function support duck-type functions it's possible for a built in function to implement all the needed features to pass the test

    Currently async frameworks have specific hacks that require creating a prototypical async generator function and taking a copy of the built in asend/aclose types for inspection

  15. kumaraditya303 commented on Dec 2, 2022

    @kumaraditya303
    kumaraditya303
    on Dec 2, 2022
    Contributor
    More actions

    now that inspect.is*function support duck-type functions it's possible for a built in function to implement all the needed features to pass the test Currently async frameworks have specific hacks that require creating a prototypical async generator function and taking a copy of the built in asend/aclose types for inspection

    So how do you propose to fix this? Can you create a PR for this to discuss?

  16. kumaraditya303
    moved this from In Progress to Todo in asyncioon Jan 9, 2023
  17. wrongnull
    added a commit that references this issue on Feb 21, 2023

    implementing checking async generator methods

    This issue will close once commit a8c7489 is merged into the 'main' branch.
    a8c7489
  18. carljm commented on Feb 22, 2023

    @carljm
    carljm
    on Feb 22, 2023
    Member
    More actions

    There is now a canonical way to mark a function that is not actually defined with async def but is known to return an awaitable, such that inspect.iscoroutinefunction will return True for it: inspect.markcoroutinefunction (see #99247)

    I think the mentioned methods of async generators should probably be marked in the same way, although that might be a bit tricky for methods implemented in C; it could involve some changes to the internal implementation details of markcoroutinefunction.

  19. wrongnull commented on Feb 23, 2023

    @wrongnull
    wrongnull
    on Feb 23, 2023
    Contributor
    More actions

    @kumaraditya303 Hi. Can you explain why aditional bifield in inderlying structures such as PyCFunctionObject isn't the way to fix this?

  20. kumaraditya303 commented on May 26, 2023

    @kumaraditya303
    kumaraditya303
    on May 26, 2023
    Contributor
    More actions

    This will never work properly because in native code we cannot distinguish between a function and a coroutine, regarding adding flags that's just going to complicate things. These aren't the only methods which return coroutine like objects, there can be more in third party code.

    The proper way to workaround this is to use inspect.isawaitable as I indicated above.

  21. kumaraditya303 commented on Aug 16, 2023

    @kumaraditya303
    kumaraditya303
    on Aug 16, 2023
    Contributor
    More actions

    I'm -1 on this, the users should use inspect.isawaitable which works in all cases.

  22. kumaraditya303
    closed this as not plannedon Aug 16, 2023
  23. github-project-automation
    moved this from Todo to Done in asyncioon Aug 16, 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

    topic-asynciotype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • asyncio
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.