+import collections as _collections
import inspect as _inspect
import operator as _operator
class DispatcherMeta(type):
def __new__(metacls, name, bases, ns):
- hooks = {}
-
+ conflicts = _collections.defaultdict(list)
for (key, value) in tuple(ns.items()):
if not isinstance(value, _core.CallHook):
continue
hook = value
for typeid in hook:
- if typeid in hooks:
- raise ValueError(f"conflicting hook: {typeid!r}")
- hooks[typeid] = hook
+ conflicts[typeid].append(key)
ns[key] = hook
+ for (typeid, keys) in conflicts.items():
+ if len(keys) > 1:
+ raise ValueError(f"dispatch conflict: {keys!r}")
+
return super().__new__(metacls, name, bases, ns)
def __init__(cls, name, bases, ns):