Skip to content

Adds ability to have subclasses for NodeVisitor and TraverserVisitor #10125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 26, 2021
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
2 changes: 2 additions & 0 deletions mypy/traverser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Generic node traverser visitor"""

from typing import List
from mypy_extensions import mypyc_attr

from mypy.visitor import NodeVisitor
from mypy.nodes import (
Expand All @@ -16,6 +17,7 @@
)


@mypyc_attr(allow_interpreted_subclasses=True)
class TraverserVisitor(NodeVisitor[None]):
"""A parse tree visitor that traverses the parse tree during visiting.

Expand Down
5 changes: 4 additions & 1 deletion mypy/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from abc import abstractmethod
from typing import TypeVar, Generic
from typing_extensions import TYPE_CHECKING
from mypy_extensions import trait
from mypy_extensions import trait, mypyc_attr

if TYPE_CHECKING:
# break import cycle only needed for mypy
Expand All @@ -14,6 +14,7 @@


@trait
@mypyc_attr(allow_interpreted_subclasses=True)
class ExpressionVisitor(Generic[T]):
@abstractmethod
def visit_int_expr(self, o: 'mypy.nodes.IntExpr') -> T:
Expand Down Expand Up @@ -193,6 +194,7 @@ def visit_temp_node(self, o: 'mypy.nodes.TempNode') -> T:


@trait
@mypyc_attr(allow_interpreted_subclasses=True)
class StatementVisitor(Generic[T]):
# Definitions

Expand Down Expand Up @@ -310,6 +312,7 @@ def visit_exec_stmt(self, o: 'mypy.nodes.ExecStmt') -> T:


@trait
@mypyc_attr(allow_interpreted_subclasses=True)
class NodeVisitor(Generic[T], ExpressionVisitor[T], StatementVisitor[T]):
"""Empty base class for parse tree node visitors.

Expand Down