Commits

Henning Schröder committed dcada9b

fix for nonlocal keyword

  • Participants
  • Parent commits 6ec1e6d

Comments (0)

Files changed (1)

File tcore/singledispatch.py

     """
     registry = {}
     dispatch_cache = WeakKeyDictionary()
-    cache_token = None
+    non_local = {"cache_token": None}
 
     def dispatch(cls):
         """generic_func.dispatch(cls) -> <function implementation>
 
         """
         #nonlocal cache_token
-        if cache_token is not None:
+        if non_local["cache_token"] is not None:
             current_token = get_cache_token()
-            if cache_token != current_token:
+            if non_local["cache_token"] != current_token:
                 dispatch_cache.clear()
-                cache_token = current_token
+                non_local["cache_token"] = current_token
         try:
             impl = dispatch_cache[cls]
         except KeyError:
         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 non_local["cache_token"] is None and hasattr(cls, '__abstractmethods__'):
+            non_local["cache_token"] = get_cache_token()
         dispatch_cache.clear()
         return func
 
     wrapper.registry = MappingProxyType(registry)
     wrapper._clear_cache = dispatch_cache.clear
     update_wrapper(wrapper, func)
-    return wrapper
+    return wrapper