From 57aca11d4a468cf9a40b93dcb3bdd0f253ead017 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 20 Aug 2020 23:51:08 +0300 Subject: [PATCH] hookspec: type annotate parent argument to pytest_collect_file --- src/_pytest/doctest.py | 3 ++- src/_pytest/hookspec.py | 8 +++++--- src/_pytest/python.py | 4 +++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/_pytest/doctest.py b/src/_pytest/doctest.py index acedd389b..c744bb369 100644 --- a/src/_pytest/doctest.py +++ b/src/_pytest/doctest.py @@ -32,6 +32,7 @@ from _pytest.compat import TYPE_CHECKING from _pytest.config import Config from _pytest.config.argparsing import Parser from _pytest.fixtures import FixtureRequest +from _pytest.nodes import Collector from _pytest.outcomes import OutcomeException from _pytest.pathlib import import_path from _pytest.python_api import approx @@ -118,7 +119,7 @@ def pytest_unconfigure() -> None: def pytest_collect_file( - path: py.path.local, parent + path: py.path.local, parent: Collector, ) -> Optional[Union["DoctestModule", "DoctestTextfile"]]: config = parent.config if path.ext == ".py": diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index 8e6be7d56..d4aaba1ec 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -274,10 +274,12 @@ def pytest_ignore_collect(path: py.path.local, config: "Config") -> Optional[boo """ -def pytest_collect_file(path: py.path.local, parent) -> "Optional[Collector]": - """Return collection Node or None for the given path. +def pytest_collect_file( + path: py.path.local, parent: "Collector" +) -> "Optional[Collector]": + """Create a Collector for the given path, or None if not relevant. - Any new node needs to have the specified ``parent`` as a parent. + The new node needs to have the specified ``parent`` as a parent. :param py.path.local path: The path to collect. """ diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 63fa539d2..7aa5b4222 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -184,7 +184,9 @@ def pytest_pyfunc_call(pyfuncitem: "Function") -> Optional[object]: return True -def pytest_collect_file(path: py.path.local, parent) -> Optional["Module"]: +def pytest_collect_file( + path: py.path.local, parent: nodes.Collector +) -> Optional["Module"]: ext = path.ext if ext == ".py": if not parent.session.isinitpath(path):