diff --git a/mypy/checker.py b/mypy/checker.py index 1c8956ae6722..f77646e791a2 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -177,8 +177,10 @@ tuple_fallback, ) from mypy.types import ( + ANY_STRATEGY, OVERLOAD_NAMES, AnyType, + BoolTypeQuery, CallableType, DeletedType, ErasedType, @@ -196,7 +198,6 @@ TypedDictType, TypeGuardedType, TypeOfAny, - TypeQuery, TypeTranslator, TypeType, TypeVarId, @@ -7081,7 +7082,7 @@ def is_valid_inferred_type(typ: Type, is_lvalue_final: bool = False) -> bool: return not typ.accept(InvalidInferredTypes()) -class InvalidInferredTypes(TypeQuery[bool]): +class InvalidInferredTypes(BoolTypeQuery): """Find type components that are not valid for an inferred type. These include type, and any types resulting from failed @@ -7089,7 +7090,7 @@ class InvalidInferredTypes(TypeQuery[bool]): """ def __init__(self) -> None: - super().__init__(any) + super().__init__(ANY_STRATEGY) def visit_uninhabited_type(self, t: UninhabitedType) -> bool: return t.ambiguous diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index b97c78cba2fc..65be472ccec7 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -5106,9 +5106,9 @@ def has_any_type(t: Type, ignore_in_type_obj: bool = False) -> bool: return t.accept(HasAnyType(ignore_in_type_obj)) -class HasAnyType(types.TypeQuery[bool]): +class HasAnyType(types.BoolTypeQuery): def __init__(self, ignore_in_type_obj: bool) -> None: - super().__init__(any) + super().__init__(types.ANY_STRATEGY) self.ignore_in_type_obj = ignore_in_type_obj def visit_any(self, t: AnyType) -> bool: @@ -5185,7 +5185,7 @@ def replace_callable_return_type(c: CallableType, new_ret_type: Type) -> Callabl return c.copy_modified(ret_type=new_ret_type) -class ArgInferSecondPassQuery(types.TypeQuery[bool]): +class ArgInferSecondPassQuery(types.BoolTypeQuery): """Query whether an argument type should be inferred in the second pass. The result is True if the type has a type variable in a callable return @@ -5194,17 +5194,17 @@ class ArgInferSecondPassQuery(types.TypeQuery[bool]): """ def __init__(self) -> None: - super().__init__(any) + super().__init__(types.ANY_STRATEGY) def visit_callable_type(self, t: CallableType) -> bool: return self.query_types(t.arg_types) or t.accept(HasTypeVarQuery()) -class HasTypeVarQuery(types.TypeQuery[bool]): +class HasTypeVarQuery(types.BoolTypeQuery): """Visitor for querying whether a type has a type variable component.""" def __init__(self) -> None: - super().__init__(any) + super().__init__(types.ANY_STRATEGY) def visit_type_var(self, t: TypeVarType) -> bool: return True @@ -5214,11 +5214,11 @@ def has_erased_component(t: Type | None) -> bool: return t is not None and t.accept(HasErasedComponentsQuery()) -class HasErasedComponentsQuery(types.TypeQuery[bool]): +class HasErasedComponentsQuery(types.BoolTypeQuery): """Visitor for querying whether a type has an erased component.""" def __init__(self) -> None: - super().__init__(any) + super().__init__(types.ANY_STRATEGY) def visit_erased_type(self, t: ErasedType) -> bool: return True @@ -5228,11 +5228,11 @@ def has_uninhabited_component(t: Type | None) -> bool: return t is not None and t.accept(HasUninhabitedComponentsQuery()) -class HasUninhabitedComponentsQuery(types.TypeQuery[bool]): +class HasUninhabitedComponentsQuery(types.BoolTypeQuery): """Visitor for querying whether a type has an UninhabitedType component.""" def __init__(self) -> None: - super().__init__(any) + super().__init__(types.ANY_STRATEGY) def visit_uninhabited_type(self, t: UninhabitedType) -> bool: return True diff --git a/mypy/semanal_shared.py b/mypy/semanal_shared.py index ee9218f02b3e..e5be4aa55cd3 100644 --- a/mypy/semanal_shared.py +++ b/mypy/semanal_shared.py @@ -21,7 +21,7 @@ TypeInfo, ) from mypy.tvar_scope import TypeVarLikeScope -from mypy.type_visitor import TypeQuery +from mypy.type_visitor import ANY_STRATEGY, BoolTypeQuery from mypy.types import ( TPDICT_FB_NAMES, FunctionLike, @@ -319,9 +319,9 @@ def paramspec_kwargs( ) -class HasPlaceholders(TypeQuery[bool]): +class HasPlaceholders(BoolTypeQuery): def __init__(self) -> None: - super().__init__(any) + super().__init__(ANY_STRATEGY) def visit_placeholder_type(self, t: PlaceholderType) -> bool: return True diff --git a/mypy/typeanal.py b/mypy/typeanal.py index 468b10fc9847..e4f56924d2d7 100644 --- a/mypy/typeanal.py +++ b/mypy/typeanal.py @@ -42,11 +42,13 @@ from mypy.tvar_scope import TypeVarLikeScope from mypy.types import ( ANNOTATED_TYPE_NAMES, + ANY_STRATEGY, FINAL_TYPE_NAMES, LITERAL_TYPE_NAMES, NEVER_NAMES, TYPE_ALIAS_NAMES, AnyType, + BoolTypeQuery, CallableArgument, CallableType, DeletedType, @@ -1944,9 +1946,9 @@ def has_any_from_unimported_type(t: Type) -> bool: return t.accept(HasAnyFromUnimportedType()) -class HasAnyFromUnimportedType(TypeQuery[bool]): +class HasAnyFromUnimportedType(BoolTypeQuery): def __init__(self) -> None: - super().__init__(any) + super().__init__(ANY_STRATEGY) def visit_any(self, t: AnyType) -> bool: return t.type_of_any == TypeOfAny.from_unimported_type @@ -2033,10 +2035,10 @@ def find_self_type(typ: Type, lookup: Callable[[str], SymbolTableNode | None]) - return typ.accept(HasSelfType(lookup)) -class HasSelfType(TypeQuery[bool]): +class HasSelfType(BoolTypeQuery): def __init__(self, lookup: Callable[[str], SymbolTableNode | None]) -> None: self.lookup = lookup - super().__init__(any) + super().__init__(ANY_STRATEGY) def visit_unbound_type(self, t: UnboundType) -> bool: sym = self.lookup(t.name) diff --git a/mypy/types.py b/mypy/types.py index bff83ba52df6..14913ba41be4 100644 --- a/mypy/types.py +++ b/mypy/types.py @@ -3301,9 +3301,9 @@ def replace_alias_tvars( return new_tp -class HasTypeVars(TypeQuery[bool]): +class HasTypeVars(BoolTypeQuery): def __init__(self) -> None: - super().__init__(any) + super().__init__(ANY_STRATEGY) self.skip_alias_target = True def visit_type_var(self, t: TypeVarType) -> bool: