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

Replace asyncio.iscoroutinefunction with inspect.iscoroutinefunction #387

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

musicinmybrain
Copy link
Contributor

Fixes DeprecationWarning on Python 3.14, although for now we still get them from pytest-asyncio; asyncio.iscoroutinefunction is scheduled for removal in Python 3.16.

https://docs.python.org/3.13/library/inspect.html#inspect.iscoroutinefunction

Fixes `DeprecationWarning` on Python 3.14, although for now we still get
them from `pytest-asyncio`; `asyncio.iscoroutinefunction` is scheduled
for removal in Python 3.16.

https://docs.python.org/3.13/library/inspect.html#inspect.iscoroutinefunction
@miguelgrinberg
Copy link
Owner

Considering that there's still 3 more versions until removal I'm going to keep things the way they are for now and apply this change once I have phased out support for 3.8 and 3.9.

@musicinmybrain
Copy link
Contributor Author

Considering that there's still 3 more versions until removal I'm going to keep things the way they are for now and apply this change once I have phased out support for 3.8 and 3.9.

Sounds reasonable to me. The documentation for inspect.iscoroutinefunction didn’t give me any reasons to expect this not to work in 3.8 and 3.9, but the CI certainly seems to be showing that there is some kind of difference in behavior between inspect.iscoroutinefunction and asyncio.iscoroutinefunction on those Python versions.

@miguelgrinberg
Copy link
Owner

The failures are caused, I think, by AsyncMock instances.

python3.8
Python 3.8.20 (default, Nov 17 2024, 10:12:25)
Type "help", "copyright", "credits" or "license" for more information.
>>> from unittest.mock import AsyncMock
>>> import inspect
>>> x = AsyncMock()
>>> inspect.iscoroutinefunction(x)
Falsepython3.13
Python 3.13.0 (main, Nov 17 2024, 23:19:47) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from unittest.mock import AsyncMock
>>> import inspect
>>> x = AsyncMock()
>>> inspect.iscoroutinefunction(x)
True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants