[Python-Dev] removing nested tuple function parameters

Steven Bethard steven.bethard at gmail.com
Mon Sep 19 17:50:01 CEST 2005

Greg Ewing wrote:
> François Pinard wrote:
> > The only practical reason to like this feature is sparing the need of
> > finding an otherwise useless name for the formal argument.
> If the argument represents a coherent enough concept
> to be passed in as a tuple in the first place, it
> should be possible to find a meaningful name for it.
> Otherwise the elements should probably be passed in
> as separate arguments.

But sometimes you don't have this option.  If I have a class that I'd
like to support an indexing operation like:

    obj[x, y]

then the natural __getitem__ signature will look like:

    def __getitem__(self, (x, y)):
Note that I definitely can't write this as:

    def __getitem__(self, x, y):
because __getitem__ is always called with a single argument, not two. 
Of course, I can give the parameter a name and do the tuple unpacking
manually (e.g. x, y = x_y), but I'm not sure I understand yet what we
gain by making __getitem__ harder to use with tuples.

I guess if tuple unpacking in function parameters goes away, I think
we should change the __getitem__ machinery so that:

    obj[x1, x2, ..., xN]

is translated to:

    obj.__getitem__(x1, x2, ..., xN)

where __getitem__ would now have to take a *args when called with tuples.

You can wordify anything if you just verb it.
        --- Bucky Katt, Get Fuzzy

More information about the Python-Dev mailing list