AttributeError when old-style classes fall through to the default

Issue #5 new
Ben Darnell
created an issue

On Python 2, an old-style class that does not match any of the explicit registrations raises an AttributeError instead of falling through to the default:

from singledispatch import singledispatch

def f(obj):

class NewStyle(object):

class OldStyle:

Traceback (most recent call last):
  File "", line 14, in <module>
  File ".../lib/python2.7/site-packages/", line 210, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
  File ".../lib/python2.7/site-packages/", line 191, in dispatch
    impl = _find_impl(cls, registry)
  File ".../lib/python2.7/site-packages/", line 142, in _find_impl
    mro = _compose_mro(cls, registry.keys())
  File ".../lib/python2.7/site-packages/", line 98, in _compose_mro
    bases = set(cls.__mro__)
AttributeError: class OldStyle has no attribute '__mro__'

Comments (1)

  1. Ben Darnell reporter

    Also, on Python 2.6, it can't be used with old-style classes even if they are explicitly registered (the cache can't make a weak reference to a class object in that version).

  2. Log in to comment