From 51863b7d6ea183167da09fc6b3f2745a1aaa4ef5 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sat, 23 Sep 2023 19:31:17 +0100 Subject: [PATCH] gh-109653: Improve `enum` import time by avoiding import of `functools` (GH-109789) --- Lib/enum.py | 5 ++--- .../Library/2023-09-23-12-47-45.gh-issue-109653.9wZBfs.rst | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2023-09-23-12-47-45.gh-issue-109653.9wZBfs.rst diff --git a/Lib/enum.py b/Lib/enum.py index 994a7b9c73f9a7..f5448a1788e4d2 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -1,8 +1,6 @@ import sys import builtins as bltns from types import MappingProxyType, DynamicClassAttribute -from operator import or_ as _or_ -from functools import reduce __all__ = [ @@ -1884,7 +1882,8 @@ def __call__(self, enumeration): missed = [v for v in values if v not in member_values] if missed: missing_names.append(name) - missing_value |= reduce(_or_, missed) + for val in missed: + missing_value |= val if missing_names: if len(missing_names) == 1: alias = 'alias %s is missing' % missing_names[0] diff --git a/Misc/NEWS.d/next/Library/2023-09-23-12-47-45.gh-issue-109653.9wZBfs.rst b/Misc/NEWS.d/next/Library/2023-09-23-12-47-45.gh-issue-109653.9wZBfs.rst new file mode 100644 index 00000000000000..1d0f0e4f83b5e1 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-09-23-12-47-45.gh-issue-109653.9wZBfs.rst @@ -0,0 +1 @@ +Reduce the import time of :mod:`enum` by over 50%. Patch by Alex Waygood.