Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into drop-pytest-asyncio
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex committed May 4, 2022
2 parents d00c026 + 6286ecc commit 873217d
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 30 deletions.
10 changes: 5 additions & 5 deletions requirements.txt
Expand Up @@ -4,8 +4,8 @@
wsproto==1.1.0

# Packaging
twine==3.4.2
wheel==0.37.0
twine==4.0.0
wheel==0.37.1

# Testing
autoflake==1.4
Expand All @@ -14,9 +14,9 @@ flake8==3.9.2
isort==5.10.1
pytest==6.2.5
pytest-mock==3.6.1
mypy==0.910
mypy==0.950
types-click==7.1.8
types-pyyaml==6.0.5
types-pyyaml==6.0.7
trustme==0.9.0
cryptography==3.4.8
coverage==6.3.2
Expand All @@ -25,4 +25,4 @@ httpx==1.0.0b0

# Documentation
mkdocs==1.3.0
mkdocs-material==8.2.5
mkdocs-material==8.2.12
2 changes: 1 addition & 1 deletion scripts/coverage
Expand Up @@ -8,4 +8,4 @@ export SOURCE_FILES="uvicorn tests"

set -x

${PREFIX}coverage report --show-missing --skip-covered --fail-under=96.87
${PREFIX}coverage report
26 changes: 18 additions & 8 deletions setup.cfg
Expand Up @@ -8,16 +8,12 @@ ignore_missing_imports = True
follow_imports = silent
files =
uvicorn/lifespan,
tests/test_lifespan.py,
uvicorn/config.py,
tests/test_config.py,
uvicorn/middleware/message_logger.py,
uvicorn/supervisors/basereload.py,
uvicorn/importer.py,
tests/importer/test_importer.py,
uvicorn/protocols/utils.py,
uvicorn/middleware/proxy_headers.py,
tests/middleware/test_proxy_headers.py,
uvicorn/loops,
uvicorn/main.py,
uvicorn/workers.py,
Expand All @@ -26,7 +22,6 @@ files =
uvicorn/supervisors/__init__.py,
uvicorn/middleware/debug.py,
uvicorn/middleware/wsgi.py,
tests/middleware/test_wsgi.py,
uvicorn/supervisors/watchgodreload.py,
uvicorn/_logging.py,
uvicorn/middleware/asgi2.py,
Expand All @@ -40,7 +35,19 @@ files =
uvicorn/middleware/__init__.py,
uvicorn/protocols/__init__.py,
uvicorn/protocols/http/__init__.py,
uvicorn/protocols/websockets/__init__.py
uvicorn/protocols/websockets/__init__.py,
tests/middleware/test_wsgi.py,
tests/middleware/test_proxy_headers.py,
tests/test_config.py,
tests/test_lifespan.py,
tests/test_main.py,
tests/test_default_headers.py,
tests/test_cli.py,
tests/conftest.py,
tests/importer,
tests/response.py,
tests/__init__.py,
tests/utils.py


[mypy-tests.*]
Expand All @@ -61,8 +68,6 @@ xfail_strict=True
filterwarnings=
# Turn warnings that aren't filtered into exceptions
error
# Workaround for Python 3.9.7 (see https://bugs.python.org/issue45097)
ignore:The loop argument is deprecated since Python 3\.8, and scheduled for removal in Python 3\.10\.:DeprecationWarning:asyncio

[coverage:run]
omit = venv/*
Expand All @@ -72,6 +77,9 @@ plugins =

[coverage:report]
precision = 2
fail_under = 97.33
show_missing = true
skip_covered = true
exclude_lines =
pragma: no cover
pragma: nocover
Expand All @@ -80,5 +88,7 @@ exclude_lines =
[coverage:coverage_conditional_plugin]
rules =
"sys_platform == 'win32'": py-win32
"sys_platform == 'linux'": py-linux
"sys_platform == 'darwin'": py-darwin
"sys_version_info >= (3, 8)": py-gte-38
"sys_version_info < (3, 8)": py-lt-38
2 changes: 1 addition & 1 deletion tests/protocols/test_http.py
Expand Up @@ -784,7 +784,7 @@ def send_fragmented_req(path):
# we skip the error on bsd systems if python is too slow
try:
sock.shutdown(socket.SHUT_RDWR)
except Exception:
except Exception: # pragma: py-linux
pass
sock.close()
return resp
Expand Down
2 changes: 1 addition & 1 deletion tests/protocols/test_websocket.py
Expand Up @@ -619,7 +619,7 @@ async def app(scope, receive, send):
async def websocket_session(url):
try:
async with websockets.connect(url):
pass
pass # pragma: no cover
except Exception:
pass

Expand Down
2 changes: 1 addition & 1 deletion tests/test_main.py
Expand Up @@ -38,7 +38,7 @@ def _has_ipv6(host):
sock = socket.socket(socket.AF_INET6)
sock.bind((host, 0))
has_ipv6 = True
except Exception:
except Exception: # pragma: no cover
pass
if sock:
sock.close()
Expand Down
11 changes: 8 additions & 3 deletions uvicorn/_logging.py
Expand Up @@ -6,6 +6,11 @@

import click

if sys.version_info < (3, 8): # pragma: py-gte-38
from typing_extensions import Literal
else: # pragma: py-lt-38
from typing import Literal

TRACE_LOG_LEVEL = 5


Expand Down Expand Up @@ -33,7 +38,7 @@ def __init__(
self,
fmt: Optional[str] = None,
datefmt: Optional[str] = None,
style: str = "%",
style: Literal["%", "{", "$"] = "%",
use_colors: Optional[bool] = None,
):
if use_colors in (True, False):
Expand Down Expand Up @@ -102,8 +107,8 @@ def formatMessage(self, record: logging.LogRecord) -> str:
full_path,
http_version,
status_code,
) = recordcopy.args
status_code = self.get_status_code(int(status_code))
) = recordcopy.args # type: ignore[misc]
status_code = self.get_status_code(int(status_code)) # type: ignore[arg-type]
request_line = "%s %s HTTP/%s" % (method, full_path, http_version)
if self.use_colors:
request_line = click.style(request_line, bold=True)
Expand Down
8 changes: 4 additions & 4 deletions uvicorn/config.py
Expand Up @@ -125,7 +125,7 @@ def create_ssl_context(
ctx = ssl.SSLContext(ssl_version)
get_password = (lambda: password) if password else None
ctx.load_cert_chain(certfile, keyfile, get_password)
ctx.verify_mode = cert_reqs
ctx.verify_mode = ssl.VerifyMode(cert_reqs)
if ca_certs:
ctx.load_verify_locations(ca_certs)
if ciphers:
Expand Down Expand Up @@ -174,7 +174,7 @@ def resolve_reload_patterns(
for j in range(len(directories)):
for k in range(j + 1, len(directories)):
if directories[j] in directories[k].parents:
children.append(directories[k])
children.append(directories[k]) # pragma: py-darwin
elif directories[k] in directories[j].parents:
children.append(directories[j])

Expand Down Expand Up @@ -238,7 +238,7 @@ def __init__(
ssl_cert_reqs: int = ssl.CERT_NONE,
ssl_ca_certs: Optional[str] = None,
ssl_ciphers: str = "TLSv1",
headers: Optional[List[List[str]]] = None,
headers: Optional[List[Tuple[str, str]]] = None,
factory: bool = False,
):
self.app = app
Expand Down Expand Up @@ -280,7 +280,7 @@ def __init__(
self.ssl_cert_reqs = ssl_cert_reqs
self.ssl_ca_certs = ssl_ca_certs
self.ssl_ciphers = ssl_ciphers
self.headers: List[List[str]] = headers or []
self.headers: List[Tuple[str, str]] = headers or []
self.encoded_headers: List[Tuple[bytes, bytes]] = []
self.factory = factory

Expand Down
2 changes: 1 addition & 1 deletion uvicorn/middleware/proxy_headers.py
Expand Up @@ -70,6 +70,6 @@ async def __call__(
]
host = self.get_trusted_client_host(x_forwarded_for_hosts)
port = 0
scope["client"] = (host, port) # type: ignore[index]
scope["client"] = (host, port) # type: ignore[arg-type]

return await self.app(scope, receive, send)
7 changes: 4 additions & 3 deletions uvicorn/server.py
Expand Up @@ -10,7 +10,7 @@
import time
from email.utils import formatdate
from types import FrameType
from typing import TYPE_CHECKING, List, Optional, Set, Tuple, Union
from typing import TYPE_CHECKING, List, Optional, Sequence, Set, Tuple, Union

import click

Expand Down Expand Up @@ -97,6 +97,7 @@ async def startup(self, sockets: list = None) -> None:
)
loop = asyncio.get_running_loop()

listeners: Sequence[socket.SocketType]
if sockets is not None:
# Explicitly passed a list of open sockets.
# We use this when the server is run from a Gunicorn worker.
Expand Down Expand Up @@ -170,7 +171,7 @@ def _share_socket(sock: socket.SocketType) -> socket.SocketType:

self.started = True

def _log_started_message(self, listeners: List[socket.SocketType]) -> None:
def _log_started_message(self, listeners: Sequence[socket.SocketType]) -> None:
config = self.config

if config.fd is not None:
Expand Down Expand Up @@ -297,7 +298,7 @@ def install_signal_handlers(self) -> None:
for sig in HANDLED_SIGNALS:
signal.signal(sig, self.handle_exit)

def handle_exit(self, sig: signal.Signals, frame: FrameType) -> None:
def handle_exit(self, sig: int, frame: Optional[FrameType]) -> None:

if self.should_exit and sig == signal.SIGINT:
self.force_exit = True
Expand Down
2 changes: 1 addition & 1 deletion uvicorn/supervisors/basereload.py
Expand Up @@ -33,7 +33,7 @@ def __init__(
self.pid = os.getpid()
self.reloader_name: Optional[str] = None

def signal_handler(self, sig: signal.Signals, frame: FrameType) -> None:
def signal_handler(self, sig: int, frame: Optional[FrameType]) -> None:
"""
A signal handler that is registered with the parent process.
"""
Expand Down
2 changes: 1 addition & 1 deletion uvicorn/supervisors/multiprocess.py
Expand Up @@ -34,7 +34,7 @@ def __init__(
self.should_exit = threading.Event()
self.pid = os.getpid()

def signal_handler(self, sig: signal.Signals, frame: FrameType) -> None:
def signal_handler(self, sig: int, frame: Optional[FrameType]) -> None:
"""
A signal handler that is registered with the parent process.
"""
Expand Down

0 comments on commit 873217d

Please sign in to comment.