[ANN] Multimethod.py -- multimethods for Python
Randall Hopper
aa8vb at yahoo.com
Tue Jan 11 11:49:24 EST 2000
Randall Hopper:
|I had the same question yesterday and did a little surfing. Basically,
|instead of switching off just the type of 'self' to determine which method
|to call, you switch off the type of other arguments as well.
|
|If you think best in implementation as I do:
|
| def f( a,b ):
| if type(a) == Type1 and type(b) == Type1: f_t1_t1(a,b)
| elif type(a) == Type1 and type(b) == Type2: f_t1_t2(a,b)
| elif type(a) == Type1 and type(b) == Type3: f_t1_t3(a,b)
To be closer to the truth, I really should have said:
if issubclass( a, Type1 ) and issubclass( b, Type1 ): f_t1_t1(a,b)
elif issubclass( a, Type1 ) and issubclass( b, Type2 ): f_t1_t2(a,b)
elif issubclass( a, Type1 ) and issubclass( b, Type3 ): f_t1_t3(a,b)
This alludes to one way multimethods can get into method resolution
troubles. If none of the multimethods' parameter signatures match the
argument types exactly, but multiple multimethods accepting compatible base
class objects as parameters exist, ...
--
Randall Hopper
aa8vb at yahoo.com
More information about the Python-list
mailing list