[Python-Dev] PEP 203 Augmented Assignment

Guido van Rossum guido@beopen.com
Thu, 27 Jul 2000 12:25:44 -0500


> >   IF there is a __getslice__ method:
> >      IF the slice step is None:
> >         call __getslice__(lo, hi)
> >      ELSE: # the slice step is not None
> >         call __getslice__(lo, hi, step)
> 
> > What's wrong with that?
> 
> Well, what happens if __getslice__ and __getitem__ both exist, and
> __getitem__ is used to handle extended slices, but __getslice__ isn't (yet)? 
> Currently, if it's a single item, __getitem__ is called. If it's a basic
> slice, __getslice__ is called. If it's an extended slice, __getitem__ is
> called.
> 
> In the above picture, __getslice__ would be called instead, with the 'wrong'
> number of arguments, and the use of extended slices would break.

Good point.  Sigh.

I suppose we could inspect the __getslice__ method's argument count
(it *is* available somewher) but that seems a hack (and could still
break if default arguments were used for something else).

Another solution: require a class variable to indicate the class's
awareness: e.g. you must define __getslice_takes_three_args__ when
__getslice__(lo, hi, step) is supported, otherwise the call goes to
__getitem__(slice(lo, hi, step)).

This is a bit like the feature flag bits in the type struct.

--Guido van Rossum (home page: http://www.pythonlabs.com/~guido/)