Using mypy, why does a generic function need at least two constrained types?

mypy doesn’t get error with the generic function which has multiple constrained types as shown below:

           # ↓↓↓  ↓↓↓↓↓
def func[T: (int, float)](num: T) -> T:
    return num * 3

But mypy gets the error with the generic function which has a single constrained type as shown below:

           # ↓↓↓
def func[T: (int,)](num: T) -> T:
    return num * 3

error: Type variable must have at least two constrained types

So using mypy, why does a generic function need at least two constrained types?

Cause if you only want int you don’t need a type variable, you just type your variable with int.

2 Likes