Skip to content

Commit 325d701

Browse files
Merge pull request #8248 from RonnyPfannschmidt/mixin-mro-position
alter the PyObjMixin to carry over typing information from Node
2 parents bcfe253 + a9e4315 commit 325d701

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

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

256255

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

269-
def listchain(self) -> List[nodes.Node]:
270-
...
262+
_ALLOW_MARKERS = True
271263

272264
@property
273265
def module(self):

0 commit comments

Comments
 (0)