Skip to content

Commit

Permalink
fix: Avoid visiting/inspecting multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Nov 28, 2021
1 parent 592c0bd commit 75a8a8b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/griffe/agents/extensions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ def attach(self, visitor: Visitor) -> None:
"""
self.visitor = visitor

def visit(self, node: ast.AST) -> None:
"""Visit a node.
Parameters:
node: The node to visit.
"""
getattr(self, f"visit_{node.kind}", lambda _: None)(node) # type: ignore[attr-defined]


class InspectorExtension(BaseInspector):
"""The object inspector extension base class, to inherit from."""
Expand All @@ -68,6 +76,14 @@ def attach(self, inspector: Inspector) -> None:
"""
self.inspector = inspector

def inspect(self, node: ObjectNode) -> None:
"""Inspect a node.
Parameters:
node: The node to inspect.
"""
getattr(self, f"inspect_{node.kind}", lambda _: None)(node)


Extension = Union[VisitorExtension, InspectorExtension]

Expand Down

0 comments on commit 75a8a8b

Please sign in to comment.