[Types-sig] tuples (was: New syntax?)
Guido van Rossum
guido@CNRI.Reston.VA.US
Mon, 20 Dec 1999 10:14:44 -0500
> On Sat, 18 Dec 1999, Paul Prescod wrote:
> > Greg Stein wrote:
> > >
> > > Bite me. :-)
> > >
> > > You do raise a good point in another post, however:
> > >
> > > def foo(*args: (Int)):
> >
> > Python should not use tuples as "read-only lists." From a type-system
> > point of view, a tuple should be a fixed-length, fixed-type data
> > structure defined at compile time.
[Greg again]
> Ideal or not, this is the current situation. *args is a tuple.
>
> Are you suggesting a particular change here? If so, then add it to your
> issues list :-) [you are maintaining one, right? :-)]
I don't think there's a good, deep reason why *args yields a tuple;
only a historical one.
I think that originally, all argument lists were internally passed
around as tuples, because (in *very* early Python) argument lists
*were* tuples.
There's no particular reason why it should be immutable -- after all
**kwargs returns a dict, which is mutable.
The only reason not to switch to tuples is backwards compatibility --
in particular there is a lot of code (e.g. in the std library) that
creates new arg lists by adding tuples to *args. This could be solved
by allowing + to operate on a mix of lists and tuples. I think the
result should yield a list.
Not a strong argument to do this, just a relaxation of Greg's argument
that *args is a tuple -- it needn't be, if we have a good reason to
change it.
--Guido van Rossum (home page: http://www.python.org/~guido/)