Skip to content
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
19 changes: 2 additions & 17 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
get_proper_type,
get_proper_types,
has_recursive_types,
has_type_vars,
is_named_instance,
split_with_prefix_and_suffix,
)
Expand Down Expand Up @@ -6350,23 +6351,7 @@ def __init__(self) -> None:

def visit_callable_type(self, t: CallableType) -> bool:
# TODO: we need to check only for type variables of original callable.
return self.query_types(t.arg_types) or t.accept(HasTypeVarQuery())


class HasTypeVarQuery(types.BoolTypeQuery):
"""Visitor for querying whether a type has a type variable component."""

def __init__(self) -> None:
super().__init__(types.ANY_STRATEGY)

def visit_type_var(self, t: TypeVarType) -> bool:
return True

def visit_param_spec(self, t: ParamSpecType) -> bool:
return True

def visit_type_var_tuple(self, t: TypeVarTupleType) -> bool:
return True
return self.query_types(t.arg_types) or has_type_vars(t)


def has_erased_component(t: Type | None) -> bool:
Expand Down
2 changes: 2 additions & 0 deletions mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3612,6 +3612,8 @@ def visit_type_alias_type(self, typ: TypeAliasType) -> None:


class HasTypeVars(BoolTypeQuery):
"""Visitor for querying whether a type has a type variable component."""

def __init__(self) -> None:
super().__init__(ANY_STRATEGY)
self.skip_alias_target = True
Expand Down