|
16 | 16 |
|
17 | 17 | from abc import get_cache_token
|
18 | 18 | from collections import namedtuple
|
19 |
| -# import types, weakref # Deferred to single_dispatch() |
| 19 | +# import weakref # Deferred to single_dispatch() |
20 | 20 | from operator import itemgetter
|
21 | 21 | from reprlib import recursive_repr
|
22 |
| -from types import MethodType |
| 22 | +from types import GenericAlias, MethodType, MappingProxyType, UnionType |
23 | 23 | from _thread import RLock
|
24 | 24 |
|
25 |
| -# Avoid importing types, so we can speedup import time |
26 |
| -GenericAlias = type(list[int]) |
27 |
| - |
28 | 25 | ################################################################################
|
29 | 26 | ### update_wrapper() and wraps() decorator
|
30 | 27 | ################################################################################
|
@@ -900,7 +897,7 @@ def singledispatch(func):
|
900 | 897 | # There are many programs that use functools without singledispatch, so we
|
901 | 898 | # trade-off making singledispatch marginally slower for the benefit of
|
902 | 899 | # making start-up of such applications slightly faster.
|
903 |
| - import types, weakref |
| 900 | + import weakref |
904 | 901 |
|
905 | 902 | registry = {}
|
906 | 903 | dispatch_cache = weakref.WeakKeyDictionary()
|
@@ -931,7 +928,7 @@ def dispatch(cls):
|
931 | 928 |
|
932 | 929 | def _is_union_type(cls):
|
933 | 930 | from typing import get_origin, Union
|
934 |
| - return get_origin(cls) in {Union, types.UnionType} |
| 931 | + return get_origin(cls) in {Union, UnionType} |
935 | 932 |
|
936 | 933 | def _is_valid_dispatch_type(cls):
|
937 | 934 | if isinstance(cls, type):
|
@@ -1008,7 +1005,7 @@ def wrapper(*args, **kw):
|
1008 | 1005 | registry[object] = func
|
1009 | 1006 | wrapper.register = register
|
1010 | 1007 | wrapper.dispatch = dispatch
|
1011 |
| - wrapper.registry = types.MappingProxyType(registry) |
| 1008 | + wrapper.registry = MappingProxyType(registry) |
1012 | 1009 | wrapper._clear_cache = dispatch_cache.clear
|
1013 | 1010 | update_wrapper(wrapper, func)
|
1014 | 1011 | return wrapper
|
|
0 commit comments