and I get an error for the second call, f((1, 2)):I still think you are mistaken. I don't think mypy has a way to spell a homogeneous arbitrary-length tuple. All uses of Tuple[...] refer to "anonymous struct" tuples.I tried this:
from typing import Tuple
def f(a: Tuple[int]) -> None:
pass
def main() -> None:
f((1,))
f((1, 2))
a.py: In function "main":
a.py, line 8: Argument 1 to "f" has incompatible type "Tuple[int, int]"; expected "Tuple[int]"--On Sun, Aug 17, 2014 at 3:46 PM, Andrew Barnert <abarnert@yahoo.com.dmarc.invalid> wrote:
On Sunday, August 17, 2014 1:34 PM, Guido van Rossum <guido@python.org> wrote:(I'm assuming you're referring to the homogeneity and arbitrary length here, not the fact that someone presumably said "list" when they meant "tuple", because otherwise the answer is trivial…)
>Where is it said that Tuple[int] is a homogeneous variable size list?
First, that's how the current typing.py interprets it: Tuple[str] is a homogeneous, arbitrary-length (although of course unchanging, because it's immutable) tuple of strings.
Second, what else _would_ it mean? If List[str] and Set[str] mean homogeneous arbitrary-length lists and sets of strs, and the same goes for Iterable[str] and MutableSequence[str] and IO[str] and AnyStr[str] and every other example in typing.py, it would be pretty surprising if it weren't the same for Tuple[str].
Third, if it didn't mean that, how would you define the argument types to any of Nick's examples? For example:
def isinstance(obj: object, types: type | Tuple[type]) -> bool:
That had better mean a homogeneous arbitrary-length tuple of types; if not, there doesn't seem to be any other way to declare its type.
--Guido van Rossum (python.org/~guido)