I have a function with two arguments:
def same_type_params(param1: Union[str, int], param2: Union[str, int]):
pass
How do I constrain that the types of param1 and param2 are equal? i.e. either both str or both int
Use a type variable:
from typing import TypeVar
T = TypeVar('T', str, int)
def same_type_params(param1: T, param2: T) -> None:
pass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With