Skip to content

Commit 6ec5d82

Browse files
author
Leo Ji
committed
fix: use "constraints and a bound" in TypeVar error message
PEP 484 uses "constraints" for the positional arguments of TypeVar (e.g. TypeVar("T", int, str)) and "bound" for the keyword argument. The existing message "cannot have both values and an upper bound" used neither term correctly. Updated to: TypeVar cannot have both constraints and a bound Closes #20973 Made-with: Cursor
1 parent 25b210d commit 6ec5d82

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4936,7 +4936,7 @@ def process_typevar_parameters(
49364936
return None
49374937
elif param_name == "bound":
49384938
if has_values:
4939-
self.fail("TypeVar cannot have both values and an upper bound", context)
4939+
self.fail("TypeVar cannot have both constraints and a bound", context)
49404940
return None
49414941
tv_arg = self.get_typevarlike_argument("TypeVar", param_name, param_value, context)
49424942
if tv_arg is None:

test-data/unit/semanal-errors.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ k = TypeVar('k', contravariant=1) # E: TypeVar "contravariant" may only be a lit
10621062

10631063
[case testMoreInvalidTypevarArguments]
10641064
from typing import TypeVar
1065-
T = TypeVar('T', int, str, bound=bool) # E: TypeVar cannot have both values and an upper bound
1065+
T = TypeVar('T', int, str, bound=bool) # E: TypeVar cannot have both constraints and a bound
10661066
S = TypeVar('S', covariant=True, contravariant=True) \
10671067
# E: TypeVar cannot be both covariant and contravariant
10681068
[builtins fixtures/bool.pyi]

0 commit comments

Comments
 (0)