from abc import get_cache_token
from collections import namedtuple
-# import types, weakref # Deferred to single_dispatch()
+# import weakref # Deferred to single_dispatch()
from operator import itemgetter
from reprlib import recursive_repr
-from types import MethodType
+from types import GenericAlias, MethodType, MappingProxyType, UnionType
from _thread import RLock
-# Avoid importing types, so we can speedup import time
-GenericAlias = type(list[int])
-
################################################################################
### update_wrapper() and wraps() decorator
################################################################################
# There are many programs that use functools without singledispatch, so we
# trade-off making singledispatch marginally slower for the benefit of
# making start-up of such applications slightly faster.
- import types, weakref
+ import weakref
registry = {}
dispatch_cache = weakref.WeakKeyDictionary()
def _is_union_type(cls):
from typing import get_origin, Union
- return get_origin(cls) in {Union, types.UnionType}
+ return get_origin(cls) in {Union, UnionType}
def _is_valid_dispatch_type(cls):
if isinstance(cls, type):
registry[object] = func
wrapper.register = register
wrapper.dispatch = dispatch
- wrapper.registry = types.MappingProxyType(registry)
+ wrapper.registry = MappingProxyType(registry)
wrapper._clear_cache = dispatch_cache.clear
update_wrapper(wrapper, func)
return wrapper