decorators and multimethods

"Martin v. Löwis" martin at v.loewis.de
Sat Aug 7 10:18:03 EDT 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