cpython icon indicating copy to clipboard operation
cpython copied to clipboard

User generic with TypeVarTuple does not check for minimal type of arguments

Open serhiy-storchaka opened this issue 3 years ago • 0 comments

The following code:

from typing import *
T = TypeVar('T')
T2 = TypeVar('T2')
Ts = TypeVarTuple('Ts')
class A(Generic[T, T2, *Ts]):
    x: List[T]
    y: List[T2]
    z: Tuple[*Ts]

A[int]

is executed without errors. It is expected to get an error because A requires at least two arguments.

Without TypeVarTuple you get helpful errors.

class B(Generic[T, T2]):
    pass

B[int]
B[int, str, bytes]
TypeError: Too few arguments for <class '__main__.B'>; actual 1, expected 2
TypeError: Too many arguments for <class '__main__.B'>; actual 3, expected 2

serhiy-storchaka avatar Nov 11 '22 15:11 serhiy-storchaka