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

Andrew Barnert abarnert at yahoo.com
Mon Aug 18 03:58:00 CEST 2014


On Sunday, August 17, 2014 6:26 PM, Ryan Hiebert <ryan at ryanhiebert.com> wrote:
 
> I’d expect that most uses of Tuple[int] to mean an arbitrary length tuple of 
> integers would be better served with Sequence[int] anyway

It would be nice if that were true, but unfortunately, Python has a long history of using tuple, and only tuple, both in the core language and in the stdlib, specifically to mean an arbitrary-length homogeneous tuple in APIs or syntax that take a single value or tuple of values.

I don't want to repeat the whole list that Nick Coghlan provided, but I would like to add that any third-party code that interacts with those parts of the syntax or stdlib has to do the same thing (e.g., an exception-logging decorator has to taken an exception type or tuple of exception types to use in an except statement), and there's probably some third-party code that's done the same thing completely independently, just because it's endorsed by the stdlib.


More information about the Python-ideas mailing list