From ae5d16be10c139da6a21eab34f7decbf93af721b Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 27 Jan 2020 20:57:32 +0100 Subject: [PATCH] typing: FSHookProxy/gethookproxy Taken out of https://github.com/pytest-dev/pytest/pull/6556. --- src/_pytest/main.py | 2 +- src/_pytest/nodes.py | 9 ++++++--- src/_pytest/python.py | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 066c885b8..e4eb4bbc8 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -436,7 +436,7 @@ class Session(nodes.FSCollector): def isinitpath(self, path): return path in self._initialpaths - def gethookproxy(self, fspath): + def gethookproxy(self, fspath: py.path.local): return super()._gethookproxy(fspath) def perform_collect(self, args=None, genitems=True): diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index f9f1f4f68..5447f2541 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -19,6 +19,7 @@ from _pytest.compat import cached_property from _pytest.compat import getfslineno from _pytest.compat import TYPE_CHECKING from _pytest.config import Config +from _pytest.config import PytestPluginManager from _pytest.fixtures import FixtureDef from _pytest.fixtures import FixtureLookupError from _pytest.fixtures import FixtureLookupErrorRepr @@ -394,12 +395,14 @@ def _check_initialpaths_for_relpath(session, fspath): class FSHookProxy: - def __init__(self, fspath, pm, remove_mods): + def __init__( + self, fspath: py.path.local, pm: PytestPluginManager, remove_mods + ) -> None: self.fspath = fspath self.pm = pm self.remove_mods = remove_mods - def __getattr__(self, name): + def __getattr__(self, name: str): x = self.pm.subset_hook_caller(name, remove_plugins=self.remove_mods) self.__dict__[name] = x return x @@ -431,7 +434,7 @@ class FSCollector(Collector): self._norecursepatterns = self.config.getini("norecursedirs") - def _gethookproxy(self, fspath): + def _gethookproxy(self, fspath: py.path.local): # check if we have the common case of running # hooks with all conftest.py files pm = self.config.pluginmanager diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 23a67d023..c30dbc477 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -578,7 +578,7 @@ class Package(Module): func = partial(_call_with_optional_argument, teardown_module, self.obj) self.addfinalizer(func) - def gethookproxy(self, fspath): + def gethookproxy(self, fspath: py.path.local): return super()._gethookproxy(fspath) def _collectfile(self, path, handle_dupes=True):