Commits

coady committed 6c9ed2d

Abstract base classes and dropped 2.5 support.

Comments (0)

Files changed (3)

 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.6 or higher, including Python 3.
 """
 
 import sys
+try:
+    from future_builtins import map, zip
+except ImportError:
+    pass
 
 class DispatchError(TypeError):
     pass
         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 if right in left.__mro__ else object) for left, right in zip(self, other)]
 
 class multimethod(dict):
     "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("{0}{1}: {2} methods found".format(self.__name__, types, len(keys)))
     def __call__(self, *args, **kwargs):
         "Resolve and dispatch to best method."
         types = tuple(map(type, args))
 
 setup(
     name='multimethod',
-    version='0.2.1+',
+    version='0.3',
     description='Multiple argument dispacthing.',
     long_description=multimethod.__doc__,
     author='Aric Coady',
         'Intended Audience :: Developers',
         'License :: OSI Approved :: Python Software Foundation License',
         'Programming Language :: Python :: 2',
-        'Programming Language :: Python :: 2.5',
         'Programming Language :: Python :: 2.6',
         'Programming Language :: Python :: 2.7',
         'Programming Language :: Python :: 3',
 import unittest
+import collections
 from multimethod import multimethod, DispatchError
 
 # roshambo
     def __new__(cls, left, right):
         return tuple.__new__(cls, (left, right))
 
-@multimethod(object, str)
+@multimethod(collections.Iterable, str)
 def join(seq, sep):
     return sep.join(map(str, seq))