[Python-ideas] Variable-length, homogeneous tuple: why? (was: Optional static typing -- the crossroads)
Łukasz Langa
lukasz at langa.pl
Mon Aug 18 01:35:11 CEST 2014
On Aug 17, 2014, at 3:46 PM, Andrew Barnert <abarnert at yahoo.com.dmarc.invalid> wrote:
> 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].
You're playing the uniformity card and usually I would agree with you. In this case, there is no uniformity between different *data structures*. Nobody expects to be able to say: int[int], dict[str], set[str: int]. Tuples were meant to be heterogenic, Raymond draws that distinction in many classes and talks he gives. On the other hand, some types are hard to be typed heterogenically, e.g. you can't reasonably specify an Iterable that yield strings except for the third yield, which is an int.
All in all, I think it's not at all confusing to say that tuple[int, int] means a point, for instance (1, 1). That being said, we will need support for homogenous tuples, too, simply because they are already in the wild. I proposed tuple[int, ...], which is explicit and obvious (if you're Polish, that is).
--
Best regards,
Łukasz Langa
WWW: http://lukasz.langa.pl/
Twitter: @llanga
IRC: ambv on #python-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140817/393a2ce8/attachment-0001.html>
More information about the Python-ideas
mailing list