[Python-3000] Immutable lists (was: Re: Type annotations: annotating generators)

Nick Coghlan ncoghlan at gmail.com
Tue May 23 11:14:25 CEST 2006


Greg Ewing wrote:
> Collin Winter wrote:
> 
>> In Python 2, sure, but if Python 3 introduces the idea that tuples
>> should be used for fixed-length structures (since Guido has said that
>> tuple[Number, Number] should be a 2-tuple of Numbers), then something
>> else needs to fill the "hashable, arbitrary-length ordered container"
>> niche.
> 
> The way to resolve this is to devise a notation for
> arbitrary-length tuple types, not to introduce a whole
> new data type and revise everyone's ideas on how a
> tuple should be used. As far as I'm aware, Guido has
> never said that tuples should *only* be used for
> fixed-length applications.

This is exactly what I was trying to get at when I suggested using "tuple[T]" 
as the notation for an arbitrary length tuple with elements of type T, and 
"T1, T2" as the notation for a 2-tuple with the first element of type T1 and 
the second element of type T2.

If "tuple[T1, T2]" is interpreted to mean the same thing as "T1, T2" does, 
then we have two ways of spelling the 2-tuple version and no way of spelling 
the arbitrary length tuple version.

Tony's suggestion of tuple[T] (where T is not a tuple instance) to mean an 
arbitrary length sequence is potentially workable, but not particularly clean 
(it means you have to write "tuple[tuple[T1, T2]]" for an arbitrary length 
tuple of 2-tuples, as "tuple[T1, T2]" would be the description of a single 
2-tuple)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-3000 mailing list