Add type hints to test.tz_stub
MODIFY
noxfile.py
noxfile.py
@@ -157,6 +157,7 @@ def mypy(session: nox.Session) -> None:
session.install("cryptography>=1.3.4")
session.install("tornado>=6.1")
session.install("pytest>=6.2")
+ session.install("types-python-dateutil")
session.install("nox")
session.run("mypy", "--version")
session.run(
@@ -165,6 +166,7 @@ def mypy(session: nox.Session) -> None:
"dummyserver",
"noxfile.py",
"test/__init__.py",
+ "test/tz_stub.py",
"test/port_helpers.py",
)

MODIFY
test/tz_stub.py
test/tz_stub.py
@@ -2,13 +2,14 @@ import datetime
import os
import time
from contextlib import contextmanager
+from typing import Generator, Optional
import pytest
from dateutil import tz
@contextmanager
-def stub_timezone_ctx(tzname):
+def stub_timezone_ctx(tzname: Optional[str]) -> Generator[None, None, None]:
"""
Switch to a locally-known timezone specified by `tzname`.
On exit, restore the previous timezone.
@@ -32,6 +33,7 @@ def stub_timezone_ctx(tzname):
if local_tz is None:
raise OSError("Cannot determine current timezone")
old_tzname = datetime.datetime.now(local_tz).tzname()
+ assert old_tzname is not None
os.environ["TZ"] = tzname
time.tzset()

Add type hints to test.tz_stub