Skip to content

Commit 58debfa

Browse files
authored
Move visit_var to NodeVisitor (from StatementVisitor) (#6547)
This regularizes things some, since Var is not a Statement but is a Node. There is still a bunch of jankiness, since a lot of other non-Statement SymbolNodes are still missing visit methods.
1 parent 1980701 commit 58debfa

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

mypy/nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ def name(self) -> str:
828828
def fullname(self) -> Bogus[str]:
829829
return self._fullname
830830

831-
def accept(self, visitor: StatementVisitor[T]) -> T:
831+
def accept(self, visitor: NodeVisitor[T]) -> T:
832832
return visitor.visit_var(self)
833833

834834
def serialize(self) -> JsonDict:

mypy/visitor.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,6 @@ def visit_nonlocal_decl(self, o: 'mypy.nodes.NonlocalDecl') -> T:
227227
def visit_decorator(self, o: 'mypy.nodes.Decorator') -> T:
228228
pass
229229

230-
@abstractmethod
231-
def visit_var(self, o: 'mypy.nodes.Var') -> T:
232-
pass
233-
234230
# Module structure
235231

236232
@abstractmethod
@@ -320,6 +316,12 @@ class NodeVisitor(Generic[T], ExpressionVisitor[T], StatementVisitor[T]):
320316
def visit_mypy_file(self, o: 'mypy.nodes.MypyFile') -> T:
321317
pass
322318

319+
# TODO: We have a visit_var method, but no visit_typeinfo or any
320+
# other non-Statement SymbolNode (accepting those will raise a
321+
# runtime error). Maybe this should be resolved in some direction.
322+
def visit_var(self, o: 'mypy.nodes.Var') -> T:
323+
pass
324+
323325
# Module structure
324326

325327
def visit_import(self, o: 'mypy.nodes.Import') -> T:
@@ -352,9 +354,6 @@ def visit_nonlocal_decl(self, o: 'mypy.nodes.NonlocalDecl') -> T:
352354
def visit_decorator(self, o: 'mypy.nodes.Decorator') -> T:
353355
pass
354356

355-
def visit_var(self, o: 'mypy.nodes.Var') -> T:
356-
pass
357-
358357
def visit_type_alias(self, o: 'mypy.nodes.TypeAlias') -> T:
359358
pass
360359

0 commit comments

Comments
 (0)