class documentation
class VisitorExtension(PartialVisitor[T]): (source)
The node visitor extension base class, to inherit from.
Subclasses must defined the when
class variable, and your custom visit_* methods.
class TypeGuardTracker(AstVisitorExtension): when = When.AFTER def visit_If(self, node: astroid.nodes.If) -> None: # self.visitor # the main visitor # self.visitor.current # the current API object # self.visitor.state # the TreeWalkingState object if not self.visitor.state.is_type_guarged and astroidutils.is_type_guard(node): self.visitor.state.is_type_guarged = True logging.getLogger('pydocspec').info('Entering TYPE_CHECKING if block') def depart_If(self, node: astroid.nodes.If) -> None: if self.visitor.state.is_type_guarged and astroidutils.is_type_guard(node): logging.getLogger('pydocspec').info('Leaving TYPE_CHECKING if block') self.visitor.state.is_type_guarged = False
See: When
Method | __init__ |
Initialize the visitor extension. |
Method | attach |
Attach the parent visitor to this extension. |
Method | walk |
Undocumented |
Method | walkabout |
Undocumented |
Instance Variable | visitor |
The parent visitor |