FEEDBACK WANTED: Type/class unification

Dylan Thurston dpt at abel.math.harvard.edu
Mon Aug 6 14:20:05 EDT 2001


In article <mailman.997118589.7448.python-list at python.org>, Skip
Montanaro wrote:

>    Dylan> The 'list' class/type has a method '__getslice__' (etc.), which
>    Dylan> uses the old and very broken interface.  I want to define a
>    Dylan> subclass for which this interface is insufficient.  If I want the
>    Dylan> new interface, I have to figure out how to hide that method.
>    Dylan> [Does anyone know how to do this?]
>
>How about
>
>    >>> class MyList(list):
>    ...   def __getslice__(self, *args):
>    ...     raise AttributeError, "__getslice__"
>    ... 
>    >>> x = MyList()
>    >>> x.__getslice__()
>    Traceback (most recent call last):
>      File "<stdin>", line 1, in ?
>      File "<stdin>", line 3, in __getslice__
>    AttributeError: __getslice__
>
>?

Thanks for the suggestion, but this doesn't improve the behaviour: I
then get things like

>>> a[2:5]
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/tmp/python-UHAMbk", line 8, in __getslice__
AttributeError: __getslice__

I don't want the __getslice__ method to be called at all.

(This method of changing APIs, calling the new function only if the
old function can't be found, strikes me as fragile, particularly in
Python where there is no data hiding.)

Best,
	Dylan Thurston



More information about the Python-list mailing list