Skip to content

Use asgiref's iscoroutinefunction in the middleware - #164

Open
Tecktron wants to merge 1 commit into
snok:mainfrom
Tecktron:fix/iscoroutinefunction-deprecation
Open

Tecktron wants to merge 1 commit into
snok:mainfrom
Tecktron:fix/iscoroutinefunction-deprecation

Conversation

@Tecktron

Copy link
Copy Markdown

Fixes #163.

  • asyncio.iscoroutinefunction is deprecated from Python 3.14 (a DeprecationWarning every time the middleware is created) and removed in 3.16, where the middleware would fail.
  • Uses asgiref.sync.iscoroutinefunction, as Django's own middleware does. Unlike inspect.iscoroutinefunction, it also recognizes callables marked with markcoroutinefunction on Python < 3.12. asgiref is
    already installed with Django, so this adds no dependency.
  • Adds tests that the middleware's mode follows get_response (including a marked callable), and that creating it raises no DeprecationWarning.

Tested on Python 3.14 / Django 6.0 and Python 3.10 / Django 4.2 with asgiref 3.6.0, the oldest version Django 4.2 allows.

asyncio.iscoroutinefunction is deprecated from Python 3.14 and will be
removed in 3.16. asgiref's version, which Django itself uses, also
recognizes callables marked with markcoroutinefunction on Python < 3.12,
which inspect.iscoroutinefunction does not.

Fixes snok#163
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.

asyncio.iscoroutinefunction DeprecationWarning on Python 3.14

1 participant