Skip to content

Commit a9e4315

Browse files
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
1 parent c9e9a59 commit a9e4315

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

changelog/8248.trivial.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Internal Restructure: let python.PyObjMixing inherit from nodes.Node to carry over typing information.

src/_pytest/python.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from typing import Sequence
2424
from typing import Set
2525
from typing import Tuple
26-
from typing import Type
2726
from typing import TYPE_CHECKING
2827
from typing import Union
2928

@@ -255,20 +254,13 @@ def pytest_pycollect_makeitem(collector: "PyCollector", name: str, obj: object):
255254
return res
256255

257256

258-
class PyobjMixin:
259-
_ALLOW_MARKERS = True
260-
261-
# Function and attributes that the mixin needs (for type-checking only).
262-
if TYPE_CHECKING:
263-
name: str = ""
264-
parent: Optional[nodes.Node] = None
265-
own_markers: List[Mark] = []
257+
class PyobjMixin(nodes.Node):
258+
"""this mix-in inherits from Node to carry over the typing information
266259
267-
def getparent(self, cls: Type[nodes._NodeType]) -> Optional[nodes._NodeType]:
268-
...
260+
as its intended to always mix in before a node
261+
its position in the mro is unaffected"""
269262

270-
def listchain(self) -> List[nodes.Node]:
271-
...
263+
_ALLOW_MARKERS = True
272264

273265
@property
274266
def module(self):

0 commit comments

Comments
 (0)