[Python-ideas] Variable-length, homogeneous tuple: why? (was: Optional static typing -- the crossroads)

Andrew Barnert abarnert at yahoo.com
Mon Aug 18 00:46:49 CEST 2014


On Sunday, August 17, 2014 1:34 PM, Guido van Rossum <guido at python.org> wrote:

>Where is it said that Tuple[int] is a homogeneous variable size list?


(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…)

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.


More information about the Python-ideas mailing list