Skip to content

Commit

Permalink
refactor: Always set parent
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Oct 14, 2021
1 parent dfece1c commit cae85de
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 13 deletions.
10 changes: 0 additions & 10 deletions src/griffe/extensions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def _visit(self, node: ast.AST, parent: ast.AST | None = None) -> None:
class Extension(_BaseVisitor):
"""The node visitor extension base class, to inherit from."""

need_parents = False
when: When

def __init__(self, main_visitor: MainVisitor) -> None:
Expand All @@ -80,15 +79,6 @@ def __init__(self, *extensions_classes: Type[Extension]) -> None:
self._classes: list[Type[Extension]] = list(extensions_classes)
self._instances: dict[When, list[Extension]] = {}

@property
def need_parents(self) -> bool:
"""Tell if any of the contained extensions needs access to the whole parents chain while visiting.
Returns:
True or False.
"""
return any(class_.need_parents for class_ in self._classes)

@property
def when_visit_starts(self) -> list[Extension]:
"""Return the visitors that run when the visit starts.
Expand Down
4 changes: 1 addition & 3 deletions src/griffe/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,8 @@ def __init__(
self.parent: AST | None = None
self.current: Module | Class | Function = None # type: ignore
self.in_decorator: bool = False
if self.extensions.need_parents:
self._visit = self._visit_set_parents # type: ignore

def _visit_set_parents(self, node: AST, parent: AST | None = None) -> None:
def _visit(self, node: AST, parent: AST | None = None) -> None:
node.parent = parent # type: ignore
self._run_specific_or_generic(node)

Expand Down

0 comments on commit cae85de

Please sign in to comment.