From 46cf001c97ae13acd022f4e264b25af20ebf6e77 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Sun, 24 Sep 2023 13:29:04 +0100 Subject: [PATCH] gh-109653: Avoid a top-level import of `types` in `functools` --- Lib/functools.py | 3 ++- .../Library/2023-09-24-13-28-35.gh-issue-109653.9IFU0B.rst | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2023-09-24-13-28-35.gh-issue-109653.9IFU0B.rst diff --git a/Lib/functools.py b/Lib/functools.py index 6cb532323b1d67..55990e742bf23f 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -19,8 +19,9 @@ # import types, weakref # Deferred to single_dispatch() from reprlib import recursive_repr from _thread import RLock -from types import GenericAlias +# Avoid importing types, so we can speedup import time +GenericAlias = type(list[int]) ################################################################################ ### update_wrapper() and wraps() decorator diff --git a/Misc/NEWS.d/next/Library/2023-09-24-13-28-35.gh-issue-109653.9IFU0B.rst b/Misc/NEWS.d/next/Library/2023-09-24-13-28-35.gh-issue-109653.9IFU0B.rst new file mode 100644 index 00000000000000..c4f5a62433a2c1 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-09-24-13-28-35.gh-issue-109653.9IFU0B.rst @@ -0,0 +1,2 @@ +Improve import time of :mod:`functools` by around 13%. Patch by Alex +Waygood.