decorators and multimethods

"Martin v. Löwis" martin at v.loewis.de
Sat Aug 7 16:18:03 CEST 2004


Michele Simionato wrote:

> foo = Generic_Function()
> 
> @addmethod(object, object, object)
> def foo(_, x, y, z):
>     return 'default'

On a second note, I would probably prefer a different notation

foo = Generic_Function()

@foo.overload(object, object, object)
def foo(_, x, y, z):
     return 'default'

This, of course, requires changes to Generic_Function, but
they could be as simple as

   def overload(self, *types):
     def decorator(f):
       self[types] = f
       return self
     return decorator

Regards,
Martin



More information about the Python-list mailing list