|
160 | 160 | ) |
161 | 161 | from mypy.traverser import TraverserVisitor, all_return_statements, has_return_statement |
162 | 162 | from mypy.treetransform import TransformVisitor |
163 | | -from mypy.type_visitor import TypeVisitor |
164 | 163 | from mypy.typeanal import check_for_explicit_any, has_any_from_unimported_type, make_optional_type |
165 | 164 | from mypy.typeops import ( |
166 | 165 | bind_self, |
@@ -290,95 +289,25 @@ class PartialTypeScope(NamedTuple): |
290 | 289 | is_local: bool |
291 | 290 |
|
292 | 291 |
|
293 | | -class InstanceDeprecatedVisitor(TypeVisitor[None]): |
| 292 | +class InstanceDeprecatedVisitor(TypeTraverserVisitor): |
294 | 293 | """Visitor that recursively checks for deprecations in nested instances.""" |
295 | 294 |
|
296 | 295 | def __init__(self, typechecker: TypeChecker, context: Context) -> None: |
297 | 296 | self.typechecker = typechecker |
298 | 297 | 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() |
321 | 299 |
|
322 | 300 | 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) |
350 | 303 |
|
351 | 304 | 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) |
353 | 308 | if ((alias := t.alias) is not None) and ((target := alias.target) is not None): |
354 | 309 | target.accept(self) |
355 | 310 |
|
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 | | - |
382 | 311 |
|
383 | 312 | class TypeChecker(NodeVisitor[None], CheckerPluginInterface): |
384 | 313 | """Mypy type checker. |
|
0 commit comments