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..b24cf6164e8e 100644 --- a/test-data/unit/check-generics.test +++ b/test-data/unit/check-generics.test @@ -3622,3 +3622,33 @@ 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] +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 +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]