File tree Expand file tree Collapse file tree 5 files changed +27
-7
lines changed Expand file tree Collapse file tree 5 files changed +27
-7
lines changed Original file line number Diff line number Diff line change 1
1
import asyncio
2
2
import contextlib
3
3
import importlib
4
+ import sys
4
5
5
6
import pytest
6
7
15
16
expected_loop = "uvloop" # pragma: py-win32
16
17
except ImportError : # pragma: py-not-win32
17
18
expected_loop = "asyncio"
19
+ except AttributeError :
20
+ if sys .version_info < (3 , 14 ):
21
+ raise
22
+ expected_loop = "asyncio"
18
23
19
24
try :
20
25
importlib .import_module ("httptools" )
Original file line number Diff line number Diff line change 1
1
from __future__ import annotations
2
2
3
3
import asyncio
4
+ import sys
4
5
from asyncio import AbstractEventLoop
5
6
6
7
import pytest
@@ -23,7 +24,7 @@ def test_asyncio_run__custom_loop_factory() -> None:
23
24
24
25
25
26
def test_asyncio_run__passing_a_non_awaitable_callback_should_throw_error () -> None :
26
- with pytest .raises (ValueError ):
27
+ with pytest .raises (TypeError if sys . version_info >= ( 3 , 14 ) else ValueError ):
27
28
asyncio_run (
28
29
lambda : None , # type: ignore
29
30
loop_factory = CustomLoop ,
Original file line number Diff line number Diff line change 5
5
from collections .abc import Callable , Coroutine
6
6
from typing import Any , TypeVar
7
7
8
+ __all__ = ["asyncio_run" , "iscoroutinefunction" ]
9
+
10
+ if sys .version_info >= (3 , 14 ):
11
+ from inspect import iscoroutinefunction
12
+ else :
13
+ from asyncio import iscoroutinefunction
14
+
8
15
_T = TypeVar ("_T" )
9
16
10
17
if sys .version_info >= (3 , 12 ):
Original file line number Diff line number Diff line change 16
16
17
17
import click
18
18
19
+ from uvicorn ._compat import iscoroutinefunction
19
20
from uvicorn ._types import ASGIApplication
20
21
from uvicorn .importer import ImportFromStringError , import_from_string
21
22
from uvicorn .logging import TRACE_LOG_LEVEL
@@ -453,10 +454,10 @@ def load(self) -> None:
453
454
if inspect .isclass (self .loaded_app ):
454
455
use_asgi_3 = hasattr (self .loaded_app , "__await__" )
455
456
elif inspect .isfunction (self .loaded_app ):
456
- use_asgi_3 = asyncio . iscoroutinefunction (self .loaded_app )
457
+ use_asgi_3 = iscoroutinefunction (self .loaded_app )
457
458
else :
458
459
call = getattr (self .loaded_app , "__call__" , None )
459
- use_asgi_3 = asyncio . iscoroutinefunction (call )
460
+ use_asgi_3 = iscoroutinefunction (call )
460
461
self .interface = "asgi3" if use_asgi_3 else "asgi2"
461
462
462
463
if self .interface == "wsgi" :
Original file line number Diff line number Diff line change 1
1
from __future__ import annotations
2
2
3
3
import asyncio
4
+ import sys
4
5
from collections .abc import Callable
5
6
6
7
7
- def auto_loop_factory (use_subprocess : bool = False ) -> Callable [[], asyncio .AbstractEventLoop ]:
8
+ def auto_loop_factory (use_subprocess : bool = False ) -> Callable [[], asyncio .AbstractEventLoop ]: # pragma: no cover
8
9
try :
9
10
import uvloop # noqa
10
11
except ImportError : # pragma: no cover
11
- from uvicorn .loops .asyncio import asyncio_loop_factory as loop_factory
12
-
13
- return loop_factory (use_subprocess = use_subprocess )
12
+ pass
13
+ except AttributeError : # pragma: no cover
14
+ if sys .version_info < (3 , 14 ):
15
+ raise
14
16
else : # pragma: no cover
15
17
from uvicorn .loops .uvloop import uvloop_loop_factory
16
18
17
19
return uvloop_loop_factory (use_subprocess = use_subprocess )
20
+
21
+ from uvicorn .loops .asyncio import asyncio_loop_factory as loop_factory
22
+
23
+ return loop_factory (use_subprocess = use_subprocess )
You can’t perform that action at this time.
0 commit comments