class Hook(object):
def __init__(self, *typeids):
for typeid in typeids:
- if not isinstance(typeid, type):
+ if not callable(typeid):
raise ValueError(typeid)
self.__typeids = typeids
return super().__init__()
return super().__new__(metacls, name, bases, ns)
def dispatch(cls, typeid=object):
- return cls.__hooks__.get(typeid)
+ hook = cls.__hooks__.get(typeid)
+ if hook is not None:
+ return hook
+ for (checker, hook) in cls.__hooks__.items():
+ if not isinstance(checker, type) and checker(typeid):
+ return hook
+ return None
class Dispatcher(metaclass=DispatcherMeta):