From 88e3871478d872390c32258794155fa9236e2821 Mon Sep 17 00:00:00 2001 From: A5rocks Date: Mon, 12 Jan 2026 12:22:33 +0900 Subject: [PATCH 1/2] Make `X[()]` count as a type application --- mypy/typeanal.py | 4 +++- test-data/unit/check-generics.test | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/mypy/typeanal.py b/mypy/typeanal.py index 34a8eea477e7..0d52a5a63bb9 100644 --- a/mypy/typeanal.py +++ b/mypy/typeanal.py @@ -2533,7 +2533,9 @@ def validate_instance(t: Instance, fail: MsgCallback, empty_tuple_index: bool) - arg_count = len(t.args) min_tv_count = sum(not tv.has_default() for tv in t.type.defn.type_vars) max_tv_count = len(t.type.type_vars) - if arg_count and (arg_count < min_tv_count or arg_count > max_tv_count): + if (arg_count or empty_tuple_index) and ( + arg_count < min_tv_count or arg_count > max_tv_count + ): fail( wrong_type_arg_count(min_tv_count, max_tv_count, str(arg_count), t.type.name), t, diff --git a/test-data/unit/check-generics.test b/test-data/unit/check-generics.test index 32975350e20a..7b3a42cbfe17 100644 --- a/test-data/unit/check-generics.test +++ b/test-data/unit/check-generics.test @@ -3622,3 +3622,11 @@ t2.foo = [B()] t2.foo = [C()] t2.foo = [1] # E: Value of type variable "T" of "foo" of "Test" cannot be "int" [builtins fixtures/property.pyi] + +[case testMissingTypeArgsInApplication] +x: list[()] = [] # E: "list" expects 1 type argument, but none given + +[case testMissingTypeArgsInApplicationStrict] +# flags: --strict +x: list[()] = [] # E: "list" expects 1 type argument, but none given \ + # E: Missing type arguments for generic type "list" From 536ffd8ee42dea28df239961e569ce662deca604 Mon Sep 17 00:00:00 2001 From: A5rocks Date: Mon, 12 Jan 2026 12:49:42 +0900 Subject: [PATCH 2/2] Add extra tests for empty TypeVarTuples --- test-data/unit/check-generics.test | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/test-data/unit/check-generics.test b/test-data/unit/check-generics.test index 7b3a42cbfe17..b24cf6164e8e 100644 --- a/test-data/unit/check-generics.test +++ b/test-data/unit/check-generics.test @@ -3624,9 +3624,31 @@ t2.foo = [1] # E: Value of type variable "T" of "foo" of "Test" cannot be "int" [builtins fixtures/property.pyi] [case testMissingTypeArgsInApplication] -x: list[()] = [] # E: "list" expects 1 type argument, but none given +from typing import Generic +from typing_extensions import Unpack, TypeVarTuple + +Ts = TypeVarTuple("Ts") + +class CanHaveZero(Generic[Unpack[Ts]]): ... + +ok1: CanHaveZero[()] +ok2: tuple[()] + +bad1: list[()] = [] # E: "list" expects 1 type argument, but none given +[builtins fixtures/tuple.pyi] [case testMissingTypeArgsInApplicationStrict] # flags: --strict -x: list[()] = [] # E: "list" expects 1 type argument, but none given \ - # E: Missing type arguments for generic type "list" +from typing import Generic +from typing_extensions import Unpack, TypeVarTuple + +Ts = TypeVarTuple("Ts") + +class CanHaveZero(Generic[Unpack[Ts]]): ... + +ok1: CanHaveZero[()] +ok2: tuple[()] + +bad1: list[()] = [] # E: "list" expects 1 type argument, but none given \ + # E: Missing type arguments for generic type "list" +[builtins fixtures/tuple.pyi]