A function can have more than one multimethod decorator.
See tests for more example usage.
-Supported on Python 2.
5 or higher, including Python 3.
+Supported on Python 2. or higher, including Python 3.
+ from future_builtins import map, zip
return self != other and self <= other
def __sub__(self, other):
"Return relative distances, assuming self >= other."
- return [
list(left.__mro__ ).index(right) for left, right in zip(self, other)]
+ return [left.__mro__.index(right) for left, right in zip(self, other)]
"A callable directed acyclic graph of methods."
keys = self.parents(types)
if keys and (len(keys) == 1 or not self.strict):
return self[min(keys, key=types.__sub__)]
- raise DispatchError("
%s%s: %d methods found" % (self.__name__, types, len(keys)))
+ raise DispatchError(" methods found"(self.__name__, types, len(keys)))
def __call__(self, *args, **kwargs):
"Resolve and dispatch to best method."
types = tuple(map(type, args))