From 5e74d683010e2610ce85c03a3e178a7c0465d930 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Thu, 2 Jul 2026 12:10:12 +0100 Subject: [PATCH] Fix error code of note about unbound type variable The note used the default `misc` error code, which was different from the error message. --- mypy/checker.py | 1 + test-data/unit/check-typevar-unbound.test | 3 +++ 2 files changed, 4 insertions(+) diff --git a/mypy/checker.py b/mypy/checker.py index 33705c98e10c3..d13b927b28f2f 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -1825,6 +1825,7 @@ def check_unbound_return_typevar(self, typ: CallableType) -> None: "Consider using the upper bound " f"{format_type(typ.ret_type.upper_bound, self.options)} instead", context=typ.ret_type, + code=TYPE_VAR, ) def check_default_params(self, item: FuncItem, body_is_trivial: bool | None = None) -> None: diff --git a/test-data/unit/check-typevar-unbound.test b/test-data/unit/check-typevar-unbound.test index 79d326f9fedf3..2dffaee6f2fe7 100644 --- a/test-data/unit/check-typevar-unbound.test +++ b/test-data/unit/check-typevar-unbound.test @@ -13,6 +13,9 @@ def g() -> U: # E: A function returning TypeVar should receive at least one argu # N: Consider using the upper bound "int" instead ... +def g2() -> U: # type: ignore[type-var] + ... + V = TypeVar('V', int, str) def h() -> V: # E: A function returning TypeVar should receive at least one argument containing the same TypeVar