Open
Description
from typing import reveal_type
def foo[T: (int, str, int | str)](*args: T) -> tuple[T, ...]:
return args
a = foo(0)
b = foo('')
c = foo(0, '')
d = foo('', 0)
reveal_type(a)
reveal_type(b)
reveal_type(c)
reveal_type(d)
$ mypy example.py
example.py:10: error: Value of type variable "T" of "foo" cannot be "object" [type-var]
example.py:11: error: Value of type variable "T" of "foo" cannot be "object" [type-var]
example.py:13: note: Revealed type is "builtins.tuple[builtins.int, ...]"
example.py:14: note: Revealed type is "builtins.tuple[builtins.str, ...]"
example.py:15: note: Revealed type is "builtins.tuple[builtins.object, ...]"
example.py:16: note: Revealed type is "builtins.tuple[builtins.object, ...]"
Found 2 errors in 1 file (checked 1 source file)
I'd expect c
and d
to be of type tuple[int | str, ...]
as allowed by the constraints on T