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 — inspect.iscorutinefunction() returns False for unittest.mock.AsyncMock instances · Issue #84753 · python/cpython

inspect.iscorutinefunction() returns False for unittest.mock.AsyncMock instances #84753

New issue
Copy link
New issue
Copy link
Closed
Closed
inspect.iscorutinefunction() returns False for unittest.mock.AsyncMock instances#84753
Copy link
Labels
3.10 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

moriyoshi
mannequin
opened on May 9, 2020
Issue body actions
BPO 40573
Nosy @moriyoshi, @1st1, @lisroach, @tirkarthi, @iritkatriel

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 2020-05-09.03:14:11.981>
labels = ['3.8', 'type-bug', 'library', '3.9', '3.10']
title = 'inspect.iscorutinefunction() returns False for unittest.mock.AsyncMock instances'
updated_at = <Date 2020-08-25.16:22:34.440>
user = 'https://github.com/moriyoshi'

bugs.python.org fields:

activity = <Date 2020-08-25.16:22:34.440>
actor = 'iritkatriel'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2020-05-09.03:14:11.981>
creator = 'moriyoshi'
dependencies = []
files = []
hgrepos = []
issue_num = 40573
keywords = []
message_count = 3.0
messages = ['368497', '368498', '375886']
nosy_count = 5.0
nosy_names = ['moriyoshi', 'yselivanov', 'lisroach', 'xtreak', 'iritkatriel']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue40573'
versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

Activity

Next
  1. moriyoshi commented on May 9, 2020

    @moriyoshi
    moriyoshimannequin
    on May 9, 2020
    MannequinAuthor
    More actions

    inspect.iscoroutinefunction() returns False for unittest.mock.AsyncMock instances while asyncio.iscoroutinefunction() returns True.

    >>> import unittest.mock
    >>> import inspect
    >>> import asyncio
    >>> inspect.iscoroutinefunction(unittest.mock.AsyncMock())
    False
    >>> asyncio.iscoroutinefunction(unittest.mock.AsyncMock())
    True
    

    Confirmed with 3.8.2 and 3.9dev

  2. moriyoshi
    added
    testsTests in the Lib/test dirTests in the Lib/test dir
    3.8 (EOL)end of lifeend of life
    3.9 (EOL)end of lifeend of life
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on May 9, 2020
  3. tirkarthi commented on May 9, 2020

    @tirkarthi
    tirkarthi
    on May 9, 2020
    Member
    More actions

    I couldn't reproduce the change in result for consecutive calls on master branch. They should return the same value.

    ./python   
    Python 3.9.0a6+ (heads/master:7f7e706d78, May  9 2020, 04:00:36) 
    [GCC 7.5.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import unittest.mock
    >>> import inspect
    >>> import asyncio
    >>> inspect.iscoroutinefunction(unittest.mock.AsyncMock())
    False
    >>> inspect.iscoroutinefunction(unittest.mock.AsyncMock())
    False
    >>> inspect.iscoroutinefunction(unittest.mock.AsyncMock())
    False
  4. tirkarthi
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    and removed
    testsTests in the Lib/test dirTests in the Lib/test dir
    on May 9, 2020
  5. iritkatriel commented on Aug 25, 2020

    @iritkatriel
    iritkatriel
    on Aug 25, 2020
    Member
    More actions

    The two implementations of iscoroutinefunction are implemented differently:

    in inspect:
    def iscoroutinefunction(obj):
    """Return true if the object is a coroutine function.
    Coroutine functions are defined with "async def" syntax.
    """
    return _has_code_flag(obj, CO_COROUTINE)

    and in asyncio:
    def iscoroutinefunction(func):
    """Return True if func is a decorated coroutine function."""
    return (inspect.iscoroutinefunction(func) or
    getattr(func, '_is_coroutine', None) is _is_coroutine)

    originally the asyncio version had only the _is_coroutine check:
    f951d28

    the inspect check was added later.

    See also bpo-28703, where the asyncio version was fixed to handle mock objects. Looks like the inspect version needs to be fixed as well.

  6. 17 remaining items

  7. miss-islington
    added a commit that references this issue on Jun 30, 2022

    pythongh-84753: Make inspect.iscoroutinefunction() work with AsyncMock (

    c2879e4
  8. ambv
    added a commit that references this issue on Jun 30, 2022

    gh-84753: Make inspect.iscoroutinefunction() work with AsyncMock (GH-…

    47f23b2
  9. ambv commented on Jun 30, 2022

    @ambv
    ambv
    on Jun 30, 2022
    Contributor
    More actions

    Fixed with #94050 and backported to 3.10 and 3.11. Thanks! ✨ 🍰 ✨

  10. ambv
    closed this as completedon Jun 30, 2022
  11. ambv
    moved this to Done in Unittest & doctest issueson Jun 30, 2022
  12. ambv
    added 2 commits that reference this issue on Jun 30, 2022

    gh-84753: Make inspect.iscoroutinefunction() work with AsyncMock (GH-…

    9ebec7d

    pythongh-84753: Clarify change made to `inspect` functions

    18695d7
  13. miss-islington
    added a commit that references this issue on Jul 5, 2022

    pythongh-84753: Clarify change made to `inspect` functions (pythonGH-…

    d1deb60
  14. pablogsal
    added a commit that references this issue on Jul 5, 2022

    gh-84753: Clarify change made to `inspect` functions (#94554)

    a2a3f2c
  15. ambv
    added a commit that references this issue on Jul 5, 2022

    gh-84753: Clarify change made to `inspect` functions (GH-94554) (GH-9…

    3472f3b
  16. miss-islington
    added a commit that references this issue on Jul 5, 2022

    pythongh-84753: Clarify change made to `inspect` functions (pythonGH-…

    44160bd
  17. ambv
    added a commit that references this issue on Jul 5, 2022

    gh-84753: Clarify change made to `inspect` functions (GH-94554) (GH-9…

    0615e7f
  18. graingert
    added a commit that references this issue on Sep 2, 2026

    Reword duck-type wording and finish the sentences

    a651bc9
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.10 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • Unittest & doctest issues
      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.