multimethods decorator

gherzig at gherzig at
Thu Oct 11 03:13:27 CEST 2007

> Gerardo Herzig a écrit :
>> Hi all. Im reading the Gido's aproach using decorators at
>> It looks good to me, but the examples shows the functionality using
>> functions.
>> Now, when i try to give this decorator into a method, if i try the
>> class test(object):
>>    @multimethod(...)
>>    def met(self, ...):
>> The multimethod decorator needs the types of the arguments, and, if the
>> met method requires self as the first argument, the multimethod should
>> look like
>> @multimethod(self.__class__, bla, ble) or some like that...
>> Now i know that im wrong, because i have this error
>>  >@multimethod(self.__class__)
>>  >NameError: name 'self' is not defined
> Indeed. Neither self (which will only be known at method call time) nor
> even the 'test' class (which is not yet defined when the decorator is
> executed) are availables.
>> So what would be the first argument to @multimethod??
> A string ?-)
Ah? And what will that string contains?
> FWIW, there's already an implementation of multiple dispacth by Mr. Eby...
Oh yes, i found the dispatch version of multimethods, but i have not tried
it yet. Do you think is better this version than Guido's?


More information about the Python-list mailing list