Skip to content

Commit

Permalink
🚨 Cover subprocess.py on mypy (#1053)
Browse files Browse the repository at this point in the history
* 🚨 Cover subprocess.py on mypy

* Update scripts/check

Co-authored-by: euri10 <euri10@users.noreply.github.com>
  • Loading branch information
Kludex and euri10 committed May 31, 2021
1 parent c68e9a7 commit 02e50c6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scripts/check
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ set -x

${PREFIX}black --check --diff --target-version=py36 $SOURCE_FILES
${PREFIX}flake8 $SOURCE_FILES
${PREFIX}mypy
${PREFIX}mypy --show-error-codes
${PREFIX}isort --check --diff --project=uvicorn $SOURCE_FILES
${PREFIX}python -m tools.cli_usage --check
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ files =
uvicorn/middleware/asgi2.py,
uvicorn/_handlers,
uvicorn/__init__.py,
uvicorn/__main__.py
uvicorn/__main__.py,
uvicorn/subprocess.py


[mypy-tests.*]
Expand Down
19 changes: 17 additions & 2 deletions uvicorn/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@
import multiprocessing
import os
import sys
from multiprocessing.context import SpawnProcess
from socket import socket
from typing import Callable, List, Optional

from uvicorn.config import Config

multiprocessing.allow_connection_pickling()
spawn = multiprocessing.get_context("spawn")


def get_subprocess(config, target, sockets):
def get_subprocess(
config: Config,
target: Callable[..., None],
sockets: List[socket],
) -> SpawnProcess:
"""
Called in the parent process, to instantiate a new child process instance.
The child is not yet started at this point.
Expand All @@ -23,6 +32,7 @@ def get_subprocess(config, target, sockets):
"""
# We pass across the stdin fileno, and reopen it in the child process.
# This is required for some debugging environments.
stdin_fileno: Optional[int]
try:
stdin_fileno = sys.stdin.fileno()
except OSError:
Expand All @@ -38,7 +48,12 @@ def get_subprocess(config, target, sockets):
return spawn.Process(target=subprocess_started, kwargs=kwargs)


def subprocess_started(config, target, sockets, stdin_fileno):
def subprocess_started(
config: Config,
target: Callable[..., None],
sockets: List[socket],
stdin_fileno: Optional[int],
) -> None:
"""
Called when the child process starts.
Expand Down

0 comments on commit 02e50c6

Please sign in to comment.