From a9e43152bc5081afccc6de6ef5526ff35c525fed Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sun, 17 Jan 2021 14:23:07 +0100 Subject: [PATCH] alter the PyObjMixin to carry over typing information from Node as PyObjMixin is always supposed to be mixed in the mro before nodes.Node the behavior doesn't change, but all the typing information carry over to help mypy. extracted from #8037 --- changelog/8248.trivial.rst | 1 + src/_pytest/python.py | 20 ++++++-------------- 2 files changed, 7 insertions(+), 14 deletions(-) create mode 100644 changelog/8248.trivial.rst diff --git a/changelog/8248.trivial.rst b/changelog/8248.trivial.rst new file mode 100644 index 000000000..0a9319d9c --- /dev/null +++ b/changelog/8248.trivial.rst @@ -0,0 +1 @@ +Internal Restructure: let python.PyObjMixing inherit from nodes.Node to carry over typing information. diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 29ebd176b..eabd7b311 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -23,7 +23,6 @@ from typing import Optional from typing import Sequence from typing import Set from typing import Tuple -from typing import Type from typing import TYPE_CHECKING from typing import Union @@ -255,21 +254,14 @@ def pytest_pycollect_makeitem(collector: "PyCollector", name: str, obj: object): return res -class PyobjMixin: +class PyobjMixin(nodes.Node): + """this mix-in inherits from Node to carry over the typing information + + as its intended to always mix in before a node + its position in the mro is unaffected""" + _ALLOW_MARKERS = True - # Function and attributes that the mixin needs (for type-checking only). - if TYPE_CHECKING: - name: str = "" - parent: Optional[nodes.Node] = None - own_markers: List[Mark] = [] - - def getparent(self, cls: Type[nodes._NodeType]) -> Optional[nodes._NodeType]: - ... - - def listchain(self) -> List[nodes.Node]: - ... - @property def module(self): """Python module object this node was collected from (can be None)."""