Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/8248.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Internal Restructure: let python.PyObjMixing inherit from nodes.Node to carry over typing information.
18 changes: 5 additions & 13 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
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

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


class PyobjMixin:
_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] = []
class PyobjMixin(nodes.Node):
"""this mix-in inherits from Node to carry over the typing information

def getparent(self, cls: Type[nodes._NodeType]) -> Optional[nodes._NodeType]:
...
as its intended to always mix in before a node
its position in the mro is unaffected"""

def listchain(self) -> List[nodes.Node]:
...
_ALLOW_MARKERS = True

@property
def module(self):
Expand Down