|
50 | 50 |
|
51 | 51 | from __future__ import annotations
|
52 | 52 |
|
53 |
| -from contextlib import contextmanager |
| 53 | +from contextlib import contextmanager, nullcontext |
54 | 54 | from typing import Any, Callable, Collection, Iterable, Iterator, List, TypeVar, cast
|
55 | 55 | from typing_extensions import Final, TypeAlias as _TypeAlias
|
56 | 56 |
|
@@ -3347,13 +3347,13 @@ def is_annotated_protocol_member(self, s: AssignmentStmt) -> bool:
|
3347 | 3347 | )
|
3348 | 3348 |
|
3349 | 3349 | def analyze_simple_literal_type(
|
3350 |
| - self, rvalue: Expression, is_final: bool, do_bools=False |
| 3350 | + self, rvalue: Expression, is_final: bool, do_inner=False |
3351 | 3351 | ) -> Type | None:
|
3352 | 3352 | """Return builtins.int if rvalue is an int literal, etc.
|
3353 | 3353 |
|
3354 | 3354 | If this is a 'Final' context, we return "Literal[...]" instead.
|
3355 | 3355 | """
|
3356 |
| - if self.function_stack and not do_bools: |
| 3356 | + if self.function_stack and not do_inner: |
3357 | 3357 | # Skip inside a function; this is to avoid confusing
|
3358 | 3358 | # the code that handles dead code due to isinstance()
|
3359 | 3359 | # inside type variables with value restrictions (like
|
@@ -4898,6 +4898,10 @@ def visit_call_expr(self, expr: CallExpr) -> None:
|
4898 | 4898 | expr.analyzed = OpExpr("divmod", expr.args[0], expr.args[1])
|
4899 | 4899 | expr.analyzed.line = expr.line
|
4900 | 4900 | expr.analyzed.accept(self)
|
| 4901 | + elif refers_to_fullname(expr.callee, "typing.TypeVar"): |
| 4902 | + for a, a_name in zip(expr.args, expr.arg_names): |
| 4903 | + with self.allow_unbound_tvars_set() if a_name == "bound" else nullcontext(): |
| 4904 | + a.accept(self) |
4901 | 4905 | else:
|
4902 | 4906 | # Normal call expression.
|
4903 | 4907 | for a in expr.args:
|
@@ -6671,7 +6675,7 @@ def is_unannotated_any(typ_: Type) -> bool:
|
6671 | 6675 | typ = None
|
6672 | 6676 | if arg.variable.is_inferred and arg.initializer:
|
6673 | 6677 | arg.initializer.accept(self)
|
6674 |
| - typ = self.analyze_simple_literal_type(arg.initializer, False, do_bools=True) |
| 6678 | + typ = self.analyze_simple_literal_type(arg.initializer, False, do_inner=True) |
6675 | 6679 | arg_types.append(typ or UntypedType())
|
6676 | 6680 | ret_type = None
|
6677 | 6681 | if self.options.default_return and self.options.disallow_untyped_defs:
|
@@ -6706,7 +6710,7 @@ def is_unannotated_any(typ_: Type) -> bool:
|
6706 | 6710 | if is_unannotated_any(defn.type.arg_types[i]):
|
6707 | 6711 | if arg.variable.is_inferred and arg.initializer:
|
6708 | 6712 | ret = self.analyze_simple_literal_type(
|
6709 |
| - arg.initializer, False, do_bools=True |
| 6713 | + arg.initializer, False, do_inner=True |
6710 | 6714 | )
|
6711 | 6715 | if ret:
|
6712 | 6716 | defn.type.arg_types[i] = ret
|
|
0 commit comments