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

Collin Winter collinw at gmail.com
Tue May 23 03:02:09 CEST 2006


On 5/22/06, Guido van Rossum <guido at python.org> wrote:
> On 5/22/06, Collin Winter <collinw at gmail.com> wrote:
> > The main use case I'm thinking of is parameterizing mapping types. Say
> > I wanted a set of Number lists: in Python 2, I'd just convert the
> > lists to tuples before adding them to the set. However, in Python 3,
> > converting the lists to tuples will cause any annotations like
> > set[list[Number]] to reject the candidate set. I'd like to avoid
> > having annotations like set[tuple & EveryElementIs(Number)]. Also,
> > before anyone proposes it, I don't think "just remove the offending
> > annotations" is a viable solution.
>
> You should be able to declare it as set[ImmutableSequence[Number]] and
> a set containing tuples would match that.

Is Python 3 going to ship with a set of these interface definitions? I
thought the plan was to leave things like this up to external
libraries, but if a crucial role for a built-in type (like what you've
described) is going to need an ImmutableSequence interface to be
correctly annotated, then....I think you can see where I'm going with
this.

Perhaps we should go with Tony Lownds' suggestion of tuple[T] is an
arbitrary-length tuple and tuple[T,] is a 1-tuple?

Collin Winter


More information about the Python-3000 mailing list