Commit aaf2016 1 parent 54d9575 commit aaf2016 Copy full SHA for aaf2016
File tree 4 files changed +27
-3
lines changed
4 files changed +27
-3
lines changed Original file line number Diff line number Diff line change 14
14
from uvicorn .config import WS_PROTOCOLS , Config
15
15
from uvicorn .lifespan .off import LifespanOff
16
16
from uvicorn .lifespan .on import LifespanOn
17
- from uvicorn .main import ServerState
18
17
from uvicorn .protocols .http .h11_impl import H11Protocol
18
+ from uvicorn .server import ServerState
19
19
20
20
try :
21
21
from uvicorn .protocols .http .httptools_impl import HttpToolsProtocol
Original file line number Diff line number Diff line change 5
5
6
6
from uvicorn .config import Config
7
7
from uvicorn .loops .auto import auto_loop_setup
8
- from uvicorn .main import ServerState
9
8
from uvicorn .protocols .http .auto import AutoHTTPProtocol
10
9
from uvicorn .protocols .websockets .auto import AutoWebSocketsProtocol
10
+ from uvicorn .server import ServerState
11
11
12
12
try :
13
13
importlib .import_module ("uvloop" )
Original file line number Diff line number Diff line change
1
+ import importlib
1
2
import inspect
2
3
import socket
3
4
from logging import WARNING
4
5
5
6
import httpx
6
7
import pytest
7
8
9
+ import uvicorn .server
8
10
from tests .utils import run_server
9
11
from uvicorn import Server
10
12
from uvicorn ._types import ASGIReceiveCallable , ASGISendCallable , Scope
@@ -113,3 +115,12 @@ async def test_exit_on_create_server_with_invalid_host() -> None:
113
115
server = Server (config = config )
114
116
await server .serve ()
115
117
assert exc_info .value .code == 1
118
+
119
+
120
+ def test_deprecated_server_state_from_main () -> None :
121
+ with pytest .deprecated_call (
122
+ match = "uvicorn.main.ServerState is deprecated, use uvicorn.server.ServerState instead."
123
+ ):
124
+ main = importlib .import_module ("uvicorn.main" )
125
+ server_state_cls = getattr (main , "ServerState" )
126
+ assert server_state_cls is uvicorn .server .ServerState
Original file line number Diff line number Diff line change 6
6
import platform
7
7
import ssl
8
8
import sys
9
+ import warnings
9
10
from configparser import RawConfigParser
10
11
from typing import IO , Any , Callable
11
12
29
30
LoopSetupType ,
30
31
WSProtocolType ,
31
32
)
32
- from uvicorn .server import Server , ServerState # noqa: F401 # Used to be defined here.
33
+ from uvicorn .server import Server
33
34
from uvicorn .supervisors import ChangeReload , Multiprocess
34
35
35
36
LEVEL_CHOICES = click .Choice (list (LOG_LEVELS .keys ()))
@@ -587,5 +588,17 @@ def run(
587
588
sys .exit (STARTUP_FAILURE )
588
589
589
590
591
+ def __getattr__ (name : str ) -> Any :
592
+ if name == "ServerState" :
593
+ warnings .warn (
594
+ "uvicorn.main.ServerState is deprecated, use uvicorn.server.ServerState instead." ,
595
+ DeprecationWarning ,
596
+ )
597
+ from uvicorn .server import ServerState
598
+
599
+ return ServerState
600
+ raise AttributeError (f"module { __name__ } has no attribute { name } " )
601
+
602
+
590
603
if __name__ == "__main__" :
591
604
main () # pragma: no cover
You can’t perform that action at this time.
0 commit comments