Skip to content

Commit 6e9d4b4

Browse files
committed
Derive InstanceDeprecatedVisitor from TypeTraverserVisitor instead of TypeVisitor.
1 parent a484f16 commit 6e9d4b4

File tree

1 file changed

+7
-78
lines changed

1 file changed

+7
-78
lines changed

mypy/checker.py

Lines changed: 7 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@
160160
)
161161
from mypy.traverser import TraverserVisitor, all_return_statements, has_return_statement
162162
from mypy.treetransform import TransformVisitor
163-
from mypy.type_visitor import TypeVisitor
164163
from mypy.typeanal import check_for_explicit_any, has_any_from_unimported_type, make_optional_type
165164
from mypy.typeops import (
166165
bind_self,
@@ -290,95 +289,25 @@ class PartialTypeScope(NamedTuple):
290289
is_local: bool
291290

292291

293-
class InstanceDeprecatedVisitor(TypeVisitor[None]):
292+
class InstanceDeprecatedVisitor(TypeTraverserVisitor):
294293
"""Visitor that recursively checks for deprecations in nested instances."""
295294

296295
def __init__(self, typechecker: TypeChecker, context: Context) -> None:
297296
self.typechecker = typechecker
298297
self.context = context
299-
self.visited: set[Type] = set()
300-
301-
def _already_visited(self, t: Type, /) -> bool:
302-
if t in self.visited:
303-
return True
304-
self.visited.add(t)
305-
return False
306-
307-
def visit_any(self, t: AnyType) -> None:
308-
pass
309-
310-
def visit_callable_type(self, t: CallableType) -> None:
311-
if not self._already_visited(t):
312-
for arg_type in t.arg_types:
313-
arg_type.accept(self)
314-
t.ret_type.accept(self)
315-
316-
def visit_deleted_type(self, t: DeletedType) -> None:
317-
pass
318-
319-
def visit_erased_type(self, t: ErasedType) -> None:
320-
pass
298+
self.seen_aliases: set[TypeAliasType] = set()
321299

322300
def visit_instance(self, t: Instance) -> None:
323-
if not self._already_visited(t):
324-
self.typechecker.check_deprecated(t.type, self.context)
325-
for arg in t.args:
326-
arg.accept(self)
327-
328-
def visit_literal_type(self, t: LiteralType) -> None:
329-
pass
330-
331-
def visit_none_type(self, t: NoneType) -> None:
332-
pass
333-
334-
def visit_overloaded(self, t: Overloaded) -> None:
335-
pass
336-
337-
def visit_param_spec(self, t: ParamSpecType) -> None:
338-
pass
339-
340-
def visit_parameters(self, t: Parameters) -> None:
341-
pass
342-
343-
def visit_partial_type(self, t: PartialType) -> None:
344-
pass
345-
346-
def visit_tuple_type(self, t: TupleType) -> None:
347-
if not self._already_visited(t):
348-
for item in t.items:
349-
item.accept(self)
301+
super().visit_instance(t)
302+
self.typechecker.check_deprecated(t.type, self.context)
350303

351304
def visit_type_alias_type(self, t: TypeAliasType) -> None:
352-
if not self._already_visited(t):
305+
super().visit_type_alias_type(t)
306+
if t not in self.seen_aliases:
307+
self.seen_aliases.add(t)
353308
if ((alias := t.alias) is not None) and ((target := alias.target) is not None):
354309
target.accept(self)
355310

356-
def visit_type_type(self, t: TypeType) -> None:
357-
pass
358-
359-
def visit_type_var(self, t: TypeVarType) -> None:
360-
pass
361-
362-
def visit_type_var_tuple(self, t: TypeVarTupleType) -> None:
363-
pass
364-
365-
def visit_typeddict_type(self, t: TypedDictType) -> None:
366-
pass
367-
368-
def visit_unbound_type(self, t: UnboundType) -> None:
369-
pass
370-
371-
def visit_uninhabited_type(self, t: UninhabitedType) -> None:
372-
pass
373-
374-
def visit_union_type(self, t: UnionType) -> None:
375-
if not self._already_visited(t):
376-
for item in t.items:
377-
item.accept(self)
378-
379-
def visit_unpack_type(self, t: UnpackType) -> None:
380-
pass
381-
382311

383312
class TypeChecker(NodeVisitor[None], CheckerPluginInterface):
384313
"""Mypy type checker.

0 commit comments

Comments
 (0)