Python allows type hints like tuple[int,...], but is there any shorthand way to verify that? [duplicate]

13 hours ago 1
ARTICLE AD BOX

Python allows argument type hints like tuple[int, ...]. Is there any built-in way accomplish something like: isinstance(x, tuple[int, ...])? I realize I can do isinstance(nums, tuple) and and then iterate through nums' contents and isinstance(num, int) each of them, but is there any easier and built-in way? If so, what's the minimum version of Python this function is supported in?

def add_nums(nums: tuple[int,...]) -> int: # Validate input: if isinstance(nums, tuple[int,...]) is False: raise TypeError(f"nums isn't a tuple of integers. You provided >{nums}<.") output = 0 for num in nums: output += num return output
Read Entire Article