|
295 | 295 | type_vars_as_args, |
296 | 296 | ) |
297 | 297 | from mypy.types_utils import is_invalid_recursive_alias, store_argument_type |
298 | | -from mypy.typevars import fill_typevars, has_no_typevars |
| 298 | +from mypy.typevars import fill_typevars |
299 | 299 | from mypy.util import correct_relative_import, is_dunder, module_prefix, unmangle, unnamed_function |
300 | 300 | from mypy.visitor import NodeVisitor |
301 | 301 |
|
@@ -2369,8 +2369,11 @@ def analyze_unbound_tvar_impl( |
2369 | 2369 | assert isinstance(sym.node, TypeVarExpr) |
2370 | 2370 | return t.name, sym.node |
2371 | 2371 |
|
2372 | | - def find_type_var_likes(self, t: Type) -> TypeVarLikeList: |
| 2372 | + def find_type_var_likes( |
| 2373 | + self, t: Type, *, include_bound_tvars: bool = False |
| 2374 | + ) -> TypeVarLikeList: |
2373 | 2375 | visitor = FindTypeVarVisitor(self, self.tvar_scope) |
| 2376 | + visitor.include_bound_tvars = include_bound_tvars |
2374 | 2377 | t.accept(visitor) |
2375 | 2378 | return visitor.type_var_likes |
2376 | 2379 |
|
@@ -5036,25 +5039,21 @@ def analyze_value_types(self, items: list[Expression]) -> list[Type]: |
5036 | 5039 | result: list[Type] = [] |
5037 | 5040 | for node in items: |
5038 | 5041 | try: |
5039 | | - analyzed = self.anal_type( |
5040 | | - self.expr_to_unanalyzed_type(node), allow_placeholder=True |
5041 | | - ) |
| 5042 | + unanalyzed_type = self.expr_to_unanalyzed_type(node) |
| 5043 | + if self.find_type_var_likes(unanalyzed_type, include_bound_tvars=True): |
| 5044 | + self.fail( |
| 5045 | + "TypeVar constraint type cannot be parametrized by type variables", node |
| 5046 | + ) |
| 5047 | + result.append(AnyType(TypeOfAny.from_error)) |
| 5048 | + continue |
| 5049 | + |
| 5050 | + analyzed = self.anal_type(unanalyzed_type, allow_placeholder=True) |
5042 | 5051 | if analyzed is None: |
5043 | 5052 | # Type variables are special: we need to place them in the symbol table |
5044 | 5053 | # soon, even if some value is not ready yet, see process_typevar_parameters() |
5045 | 5054 | # for an example. |
5046 | 5055 | analyzed = PlaceholderType(None, [], node.line) |
5047 | | - |
5048 | | - # has_no_typevars does not work with PlaceholderType. |
5049 | | - if not isinstance( |
5050 | | - get_proper_type(analyzed), PlaceholderType |
5051 | | - ) and not has_no_typevars(analyzed): |
5052 | | - self.fail( |
5053 | | - "TypeVar constraint type cannot be parametrized by type variables", node |
5054 | | - ) |
5055 | | - result.append(AnyType(TypeOfAny.from_error)) |
5056 | | - else: |
5057 | | - result.append(analyzed) |
| 5056 | + result.append(analyzed) |
5058 | 5057 | except TypeTranslationError: |
5059 | 5058 | self.fail("Type expected", node) |
5060 | 5059 | result.append(AnyType(TypeOfAny.from_error)) |
|
0 commit comments