Add rudimentary mypy type checking

Add a very lax mypy configuration, add it to tox -e linting, and
fix/ignore the few errors that come up. The idea is to get it running
before diving in too much.

This enables:

- Progressively adding type annotations and enabling more strict
  options, which will improve the codebase (IMO).

- Annotating the public API in-line, and eventually exposing it to
  library users who use type checkers (with a py.typed file).

Though, none of this is done yet.

Refs https://github.com/pytest-dev/pytest/issues/3342.
This commit is contained in:
Ran Benita
2019-07-08 10:04:19 +03:00
committed by Anthony Sottile
parent 628ff4d619
commit 89dfde9535
30 changed files with 104 additions and 45 deletions

View File

@@ -6,6 +6,8 @@ import warnings
from collections import defaultdict
from collections import deque
from collections import OrderedDict
from typing import Dict
from typing import Tuple
import attr
import py
@@ -31,6 +33,9 @@ from _pytest.deprecated import FIXTURE_NAMED_REQUEST
from _pytest.outcomes import fail
from _pytest.outcomes import TEST_OUTCOME
if False: # TYPE_CHECKING
from typing import Type
@attr.s(frozen=True)
class PseudoFixtureDef:
@@ -54,10 +59,10 @@ def pytest_sessionstart(session):
session._fixturemanager = FixtureManager(session)
scopename2class = {}
scopename2class = {} # type: Dict[str, Type[nodes.Node]]
scope2props = dict(session=())
scope2props = dict(session=()) # type: Dict[str, Tuple[str, ...]]
scope2props["package"] = ("fspath",)
scope2props["module"] = ("fspath", "module")
scope2props["class"] = scope2props["module"] + ("cls",)
@@ -960,7 +965,8 @@ class FixtureFunctionMarker:
scope = attr.ib()
params = attr.ib(converter=attr.converters.optional(tuple))
autouse = attr.ib(default=False)
ids = attr.ib(default=None, converter=_ensure_immutable_ids)
# Ignore type because of https://github.com/python/mypy/issues/6172.
ids = attr.ib(default=None, converter=_ensure_immutable_ids) # type: ignore
name = attr.ib(default=None)
def __call__(self, function):