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

Ryan Hiebert ryan at ryanhiebert.com
Mon Aug 18 04:18:57 CEST 2014


> On Aug 17, 2014, at 8:58 PM, Andrew Barnert <abarnert at yahoo.com> wrote:
> 
> 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.

Thanks. As I read more, I’m recalling some apis that use tuples as special markers for iterables rather than, say, strings, so that there can be polymorphism based on the arguments, allowing both a string and a tuple. Iterable strings bite again ;-)


More information about the Python-ideas mailing list