Skip to content

Commit f38f629

Browse files
authored
Fix a deprecation warning in Python 3.14
1 parent 66f0917 commit f38f629

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/quart/app.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import warnings
88
from collections import defaultdict
99
from datetime import timedelta
10-
from inspect import isasyncgen, isgenerator
10+
from inspect import isasyncgen, iscoroutinefunction as _inspect_iscoroutinefunction, isgenerator
1111
from types import TracebackType
1212
from typing import (
1313
Any,
@@ -127,6 +127,15 @@
127127
except ImportError:
128128
from typing_extensions import ParamSpec # type: ignore
129129

130+
# Python 3.14 deprecated asyncio.iscoroutinefunction, but suggested
131+
# inspect.iscoroutinefunction does not work correctly in some Python
132+
# versions before 3.12.
133+
# See https://github.com/python/cpython/issues/122858#issuecomment-2466239748
134+
if sys.version_info >= (3, 12):
135+
iscoroutinefunction = _inspect_iscoroutinefunction
136+
else:
137+
iscoroutinefunction = asyncio.iscoroutinefunction
138+
130139
AppOrBlueprintKey = Optional[str] # The App key is None, whereas blueprints are named
131140
T_after_serving = TypeVar("T_after_serving", bound=AfterServingCallable)
132141
T_after_websocket = TypeVar("T_after_websocket", bound=AfterWebsocketCallable)
@@ -1130,7 +1139,7 @@ def ensure_async(
11301139
run. Before Quart 0.11 this did not run the synchronous code
11311140
in an executor.
11321141
"""
1133-
if asyncio.iscoroutinefunction(func):
1142+
if iscoroutinefunction(func):
11341143
return func
11351144
else:
11361145
return self.sync_to_async(cast(Callable[P, T], func))

0 commit comments

Comments
 (0)