diff options
Diffstat (limited to 'singledispatch.py')
-rw-r--r-- | singledispatch.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/singledispatch.py b/singledispatch.py index b428920..87603fd 100644 --- a/singledispatch.py +++ b/singledispatch.py @@ -148,7 +148,7 @@ def _find_impl(cls, registry): if (t in registry and t not in cls.__mro__ and match not in cls.__mro__ and not issubclass(match, t)): - raise RuntimeError("Ambiguous dispatch: {} or {}".format( + raise RuntimeError("Ambiguous dispatch: {0} or {1}".format( match, t)) break if t in registry: @@ -167,7 +167,8 @@ def singledispatch(func): """ registry = {} dispatch_cache = WeakKeyDictionary() - cache_token = None + def ns(): pass + ns.cache_token = None def dispatch(cls): """generic_func.dispatch(cls) -> <function implementation> @@ -176,12 +177,11 @@ def singledispatch(func): for the given *cls* registered on *generic_func*. """ - nonlocal cache_token - if cache_token is not None: + if ns.cache_token is not None: current_token = get_cache_token() - if cache_token != current_token: + if ns.cache_token != current_token: dispatch_cache.clear() - cache_token = current_token + ns.cache_token = current_token try: impl = dispatch_cache[cls] except KeyError: @@ -198,12 +198,11 @@ def singledispatch(func): Registers a new implementation for the given *cls* on a *generic_func*. """ - nonlocal cache_token if func is None: return lambda f: register(cls, f) registry[cls] = func - if cache_token is None and hasattr(cls, '__abstractmethods__'): - cache_token = get_cache_token() + if ns.cache_token is None and hasattr(cls, '__abstractmethods__'): + ns.cache_token = get_cache_token() dispatch_cache.clear() return func @@ -217,3 +216,4 @@ def singledispatch(func): wrapper._clear_cache = dispatch_cache.clear update_wrapper(wrapper, func) return wrapper + |