From: Dmitry Selyutin Date: Tue, 13 Jun 2023 22:38:43 +0000 (+0300) Subject: dispatcher: provide better conflicts diagnostics X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c815dad789488759ebc146322146c6defbe9373a;p=mdis.git dispatcher: provide better conflicts diagnostics --- diff --git a/src/mdis/dispatcher.py b/src/mdis/dispatcher.py index 009f946..c2c85f4 100644 --- a/src/mdis/dispatcher.py +++ b/src/mdis/dispatcher.py @@ -1,3 +1,4 @@ +import collections as _collections import inspect as _inspect import operator as _operator @@ -6,18 +7,19 @@ from . import core as _core 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):