yield from self.__typeids
def __repr__(self):
- return f"{self.__class__.__name__}({self.__typeids})"
+ return f"{self.__class__.__name__}({self.__typeids!r})"
def __call__(self, call):
if not callable(call):
self.__call = call
return super().__init__()
- def __repr__(self):
- return f"{self.__class__.__name__}(call={self.call!r}, typeids={self.typeids!r})"
-
- @property
- def typeids(self):
- return self.__typeids
+ def __iter__(self):
+ yield from self.__typeids
- @property
- def call(self):
- return self.__call
+ def __repr__(self):
+ return f"{self.__class__.__name__}(call={self.__call!r}, typeids={self.__typeids!r})"
def __call__(self, dispatcher, instance):
return self.__call(dispatcher, instance)
for (key, value) in tuple(ns.items()):
if not isinstance(value, _core.CallHook):
continue
- hook = ns.pop(key)
- for typeid in hook.typeids:
+ hook = value
+ for typeid in hook:
if typeid in hooks:
raise ValueError(f"conflicting hook: {typeid!r}")
hooks[typeid] = hook
- site = hook.call.__name__
- ns[site] = hook
+ ns[key] = hook
return super().__new__(metacls, name, bases, ns)
hooks = {}
for hook in map(_operator.itemgetter(1), _inspect.getmembers(cls,
predicate=lambda member: isinstance(member, _core.CallHook))):
- for typeid in hook.typeids:
+ for typeid in hook:
hooks[typeid] = hook
cls.__hooks = hooks
return super().__init__(name, bases, ns)