[Python-3000] Implementations: A syntax for extending method dispatching beyond type/class inheritance
python3000 at davious.org
Thu Dec 7 16:37:24 CET 2006
on 12/7/2006 10:06 AM Hasan Diwan wrote:
> The parametrized version of the pass keyword could be used to indicate a
> formal interface.
> I may be missing something here, but we already have a mechanism for
> defining that a object defines certain methods. Could we not keep it
> orthogonal and have, e. g.:
> class super():
> def __init__(self): pass
> def typeOfSuper(self): pass(subclass)
> The way pass is defined now would remain the default. A new builtin
> pass() would be added to support your notion of interfaces.
I feel on a different page from you.
My best guess it is that
is ceding its implementation to its subclasses, kind of like what an
abstract class or interface would do
but I feel my guess is wrong. Please clarify.
>> def add_key_value_pair(arg: MutableContainer.add, key, value):
>> arg[key] = value
> def __add__(self, onemore):
> MutableContainer.add (self, onemore.key, onemore.value):
I'm not getting the insight you are trying to convey by contrasting
these two functions.
The former is an example of someone writing a function whose first
parameter is expected to be any object that is derived from
MutableContainer (including dict), or is derived from a class that
implements MutableContainer (including those implementing dict), or is
derived from a class that specifically implements MutableContainer.add
using a declaration like:
def add(self, key, value):
The later seems to be a class method which uses MutableContainer's add
method to add any object that has a key and a value attribute.
More information about the Python-3000