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

Guido van Rossum guido at python.org
Tue May 23 04:50:50 CEST 2006


On 5/22/06, Collin Winter <collinw at gmail.com> wrote:
> 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.

No, I can't. Will you please stop asking questions about what will
happen? We're still in the brainstorming phase. We can't know what
will happen, nor even what we'd like to happen. We need to brainstorm
more.

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

Looks pretty ugly to me. I suggest you STOP WORRYING about this for a
while and finish the rest of the PEP.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list