Skip to content

Commit

Permalink
🚨 Cover supervisors/statreload.py on mypy (#1060)
Browse files Browse the repository at this point in the history
Co-authored-by: euri10 <[email protected]>
  • Loading branch information
Kludex and euri10 authored Jun 1, 2021
1 parent 81c626a commit b4b860c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ files =
uvicorn/__init__.py,
uvicorn/__main__.py,
uvicorn/subprocess.py,
uvicorn/supervisors/statreload.py,
uvicorn/supervisors/multiprocess.py


Expand Down
14 changes: 11 additions & 3 deletions uvicorn/supervisors/statreload.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import logging
import os
from pathlib import Path
from socket import socket
from typing import Callable, Iterator, List, Optional

from uvicorn.config import Config
from uvicorn.supervisors.basereload import BaseReload

logger = logging.getLogger("uvicorn.error")


class StatReload(BaseReload):
def __init__(self, config, target, sockets):
def __init__(
self,
config: Config,
target: Callable[[Optional[List[socket]]], None],
sockets: List[socket],
) -> None:
super().__init__(config, target, sockets)
self.reloader_name = "statreload"
self.mtimes = {}

def should_restart(self):
def should_restart(self) -> bool:
for filename in self.iter_py_files():
try:
mtime = os.path.getmtime(filename)
Expand All @@ -33,7 +41,7 @@ def should_restart(self):
return True
return False

def iter_py_files(self):
def iter_py_files(self) -> Iterator[str]:
for reload_dir in self.config.reload_dirs:
for subdir, dirs, files in os.walk(reload_dir):
for file in files:
Expand Down

0 comments on commit b4b860c

Please sign in to comment.