From 2508a3176f0488809678f8bdf92efde8b6b36a91 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Sun, 18 Jun 2023 21:36:20 +0300 Subject: [PATCH] dispatcher: eliminate hidden imports --- src/mdis/dispatcher.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/mdis/dispatcher.py b/src/mdis/dispatcher.py index 7c41785..3825b9e 100644 --- a/src/mdis/dispatcher.py +++ b/src/mdis/dispatcher.py @@ -1,6 +1,12 @@ -import collections as _collections -import inspect as _inspect -import types as _types +__all__ = [ + "Dispatcher", + "DispatcherMeta", + "Hook", +] + +import collections +import inspect +import types class Hook(object): @@ -40,11 +46,11 @@ class DispatcherMeta(type): ishook = lambda member: isinstance(member, Hook) for basecls in reversed(bases): - members = _inspect.getmembers(basecls, predicate=ishook) + members = inspect.getmembers(basecls, predicate=ishook) for (_, hook) in members: hooks.update(dict.fromkeys(hook, hook)) - conflicts = _collections.defaultdict(list) + conflicts = collections.defaultdict(list) for (key, value) in tuple(ns.items()): if not ishook(value): continue @@ -58,7 +64,7 @@ class DispatcherMeta(type): if len(keys) > 1: raise ValueError(f"dispatch conflict: {keys!r}") - ns["__hooks__"] = _types.MappingProxyType(hooks) + ns["__hooks__"] = types.MappingProxyType(hooks) return super().__new__(metacls, name, bases, ns) -- 2.30.2