Skip to content

Commit

Permalink
Improve type hints on test_http.py and test_websockets.py (#2219)
Browse files Browse the repository at this point in the history
* Improve type hints on `test_http.py` and `test_websockets.py`

* Fix test_logging file

* fix linter
  • Loading branch information
Kludex authored Jan 20, 2024
1 parent afed732 commit 04c1974
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 197 deletions.
15 changes: 13 additions & 2 deletions tests/middleware/test_logging.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import contextlib
import logging
import socket
Expand All @@ -13,8 +15,17 @@
from uvicorn import Config

if typing.TYPE_CHECKING:
import sys

from uvicorn.protocols.websockets.websockets_impl import WebSocketProtocol
from uvicorn.protocols.websockets.wsproto_impl import WSProtocol
from uvicorn.protocols.websockets.wsproto_impl import WSProtocol as _WSProtocol

if sys.version_info >= (3, 10): # pragma: no cover
from typing import TypeAlias
else: # pragma: no cover
from typing_extensions import TypeAlias

WSProtocol: TypeAlias = "type[WebSocketProtocol | _WSProtocol]"


@contextlib.contextmanager
Expand Down Expand Up @@ -87,7 +98,7 @@ async def test_trace_logging_on_http_protocol(

@pytest.mark.anyio
async def test_trace_logging_on_ws_protocol(
ws_protocol_cls: "typing.Type[WSProtocol | WebSocketProtocol]",
ws_protocol_cls: WSProtocol,
caplog,
logging_config,
unused_tcp_port: int,
Expand Down
Loading

0 comments on commit 04c1974

Please sign in to comment.