Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

🐛 Fixinspect.getcoroutinefunction() can break testing withunittest.mock.patch()#14022

Merged
tiangolo merged 3 commits intofastapi:masterfrom
secrett2633:switch-iscoroutinefunction
Sep 20, 2025
Merged

🐛 Fixinspect.getcoroutinefunction() can break testing withunittest.mock.patch()#14022
tiangolo merged 3 commits intofastapi:masterfrom
secrett2633:switch-iscoroutinefunction

Conversation

@secrett2633
Copy link
Contributor

Description

This issue is related to a known Python bug that was fixed in Python 3.13 but has not been backported to earlier versions:python/cpython#94924
As a workaround for versions prior to Python 3.13, we could consider using conditional imports based on the Python version:

Resolves#14021

if sys.version_info < (3, 13):    from asyncio import iscoroutinefunctionelse:    from inspect import iscoroutinefunction

Example Code

importsysimportasyncioimportinspectfromunittest.mockimportcreate_autospec,patchprint(f"Python version:{sys.version_info[:2]}")# (3, 12)asyncdeffoo():passmock_autospec=create_autospec(foo)print(asyncio.iscoroutinefunction(mock_autospec))# Trueprint(inspect.iscoroutinefunction(mock_autospec))# Falsewithpatch('__main__.foo',autospec=True)asmock_foo:print(asyncio.iscoroutinefunction(mock_foo))# Trueprint(inspect.iscoroutinefunction(mock_foo))# False

injae-kim reacted with thumbs up emojiinjae-kim reacted with heart emojiinjae-kim reacted with rocket emoji
@YuriiMotovYuriiMotov changed the title🐛 Fix inspect.getcoroutinefunction() can break testing with unittest.mock.patch()🐛 Fixinspect.getcoroutinefunction() can break testing withunittest.mock.patch()Aug 31, 2025
@YuriiMotovYuriiMotov added the bugSomething isn't working labelAug 31, 2025
Copy link
Member

@YuriiMotovYuriiMotov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM

Thanks!

secrett2633 reacted with thumbs up emojisecrett2633 reacted with heart emoji
Copy link
Member

@tiangolotiangolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nice, thank you! 🚀 🍰

@tiangolotiangolo merged commitc831cdb intofastapi:masterSep 20, 2025
31 of 32 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@tiangolotiangolotiangolo approved these changes

@YuriiMotovYuriiMotovYuriiMotov approved these changes

Assignees

No one assigned

Labels

bugSomething isn't working

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@secrett2633@tiangolo@YuriiMotov

[8]ページ先頭

©2009-2026 Movatter.jp