Skip to content
2 changes: 1 addition & 1 deletion mypy/message_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def with_additional_msg(self, info: str) -> ErrorMessage:
TYPEVAR_ARG_MUST_BE_TYPE: Final = '{} "{}" must be a type'
TYPEVAR_UNEXPECTED_ARGUMENT: Final = 'Unexpected argument to "TypeVar()"'
UNBOUND_TYPEVAR: Final = (
"A function returning TypeVar should receive at least one argument containing the same TypeVar"
"A function returning TypeVar should have at least one same TypeVar parameter"
)
TYPE_PARAMETERS_SHOULD_BE_DECLARED: Final = (
"All type parameters should be declared ({} not declared)"
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -3716,7 +3716,7 @@ def error(u_c: Type[U]) -> P: # Error here, see below
return new_pro(u_c) # Error here, see below
[out]
main:11: note: Revealed type is "__main__.WizUser"
main:12: error: A function returning TypeVar should receive at least one argument containing the same TypeVar
main:12: error: A function returning TypeVar should have at least one same TypeVar parameter
main:12: note: Consider using the upper bound "ProUser" instead
main:13: error: Value of type variable "P" of "new_pro" cannot be "U"
main:13: error: Incompatible return value type (got "U", expected "P")
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-errorcodes.test
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ z: y # E: Variable "__main__.y" is not valid as a type [valid-type] \
from typing import TypeVar

T = TypeVar('T')
def f() -> T: pass # E: A function returning TypeVar should receive at least one argument containing the same TypeVar [type-var]
def f() -> T: pass # E: A function returning TypeVar should have at least one same TypeVar parameter [type-var]
x = f() # E: Need type annotation for "x" [var-annotated]
y = [] # E: Need type annotation for "y" (hint: "y: list[<type>] = ...") [var-annotated]
[builtins fixtures/list.pyi]
Expand Down
10 changes: 5 additions & 5 deletions test-data/unit/check-generics.test
Original file line number Diff line number Diff line change
Expand Up @@ -1599,9 +1599,9 @@ A = TypeVar('A')
B = TypeVar('B')

def f1(x: A) -> A: ...
def f2(x: A) -> B: ... # E: A function returning TypeVar should receive at least one argument containing the same TypeVar
def f2(x: A) -> B: ... # E: A function returning TypeVar should have at least one same TypeVar parameter
def f3(x: B) -> B: ...
def f4(x: int) -> A: ... # E: A function returning TypeVar should receive at least one argument containing the same TypeVar
def f4(x: int) -> A: ... # E: A function returning TypeVar should have at least one same TypeVar parameter

y1 = f1
if int():
Expand Down Expand Up @@ -1650,8 +1650,8 @@ B = TypeVar('B')
T = TypeVar('T')
def outer(t: T) -> None:
def f1(x: A) -> A: ...
def f2(x: A) -> B: ... # E: A function returning TypeVar should receive at least one argument containing the same TypeVar
def f3(x: T) -> A: ... # E: A function returning TypeVar should receive at least one argument containing the same TypeVar
def f2(x: A) -> B: ... # E: A function returning TypeVar should have at least one same TypeVar parameter
def f3(x: T) -> A: ... # E: A function returning TypeVar should have at least one same TypeVar parameter
def f4(x: A) -> T: ...
def f5(x: T) -> T: ...

Expand Down Expand Up @@ -1818,7 +1818,7 @@ from typing import TypeVar
A = TypeVar('A')
B = TypeVar('B')
def f1(x: int, y: A) -> A: ...
def f2(x: int, y: A) -> B: ... # E: A function returning TypeVar should receive at least one argument containing the same TypeVar
def f2(x: int, y: A) -> B: ... # E: A function returning TypeVar should have at least one same TypeVar parameter
def f3(x: A, y: B) -> B: ...
g = f1
g = f2
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-inference.test
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ def ff() -> None:
x = f() # E: Need type annotation for "x"
reveal_type(x) # N: Revealed type is "Any"

def f() -> T: pass # E: A function returning TypeVar should receive at least one argument containing the same TypeVar
def f() -> T: pass # E: A function returning TypeVar should have at least one same TypeVar parameter
def g(a: T) -> None: pass

g(None) # Ok
Expand Down Expand Up @@ -2693,7 +2693,7 @@ def main() -> None:
[case testDontMarkUnreachableAfterInferenceUninhabited]
from typing import TypeVar
T = TypeVar('T')
def f() -> T: pass # E: A function returning TypeVar should receive at least one argument containing the same TypeVar
def f() -> T: pass # E: A function returning TypeVar should have at least one same TypeVar parameter

class C:
x = f() # E: Need type annotation for "x"
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-parameter-specification.test
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ def callback(func: Callable[[Any], Any]) -> None: ...
class Job(Generic[P]): ...

@callback
def run_job(job: Job[...]) -> T: ... # E: A function returning TypeVar should receive at least one argument containing the same TypeVar
def run_job(job: Job[...]) -> T: ... # E: A function returning TypeVar should have at least one same TypeVar parameter
[builtins fixtures/tuple.pyi]

[case testTupleAndDictOperationsOnParamSpecArgsAndKwargs]
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-selftype.test
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ class C:
def meth(cls) -> Self: ...
@staticmethod
def bad() -> Self: ... # E: Static methods cannot use Self type \
# E: A function returning TypeVar should receive at least one argument containing the same TypeVar \
# E: A function returning TypeVar should have at least one same TypeVar parameter \
# N: Consider using the upper bound "C" instead

class D(C): ...
Expand Down
6 changes: 3 additions & 3 deletions test-data/unit/check-typevar-unbound.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ from typing import TypeVar

T = TypeVar('T')

def f() -> T: # E: A function returning TypeVar should receive at least one argument containing the same TypeVar
def f() -> T: # E: A function returning TypeVar should have at least one same TypeVar parameter
...
f()

U = TypeVar('U', bound=int)

def g() -> U: # E: A function returning TypeVar should receive at least one argument containing the same TypeVar \
def g() -> U: # E: A function returning TypeVar should have at least one same TypeVar parameter \
# N: Consider using the upper bound "int" instead
...

V = TypeVar('V', int, str)

def h() -> V: # E: A function returning TypeVar should receive at least one argument containing the same TypeVar
def h() -> V: # E: A function returning TypeVar should have at least one same TypeVar parameter
...

[case testInnerFunctionTypeVar]
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-unreachable-code.test
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ from typing import TypeVar

T = TypeVar("T")
class Foo:
def __setitem__(self, key: str, value: str) -> T: # E: A function returning TypeVar should receive at least one argument containing the same TypeVar
def __setitem__(self, key: str, value: str) -> T: # E: A function returning TypeVar should have at least one same TypeVar parameter
raise Exception

def f() -> None:
Expand Down