From ba6ea52423d6b0d976c54b7effa218ce1fef1808 Mon Sep 17 00:00:00 2001 From: Ethan Furman Date: Wed, 26 Dec 2018 10:46:03 -0800 Subject: Revert "Speed-up building enums by value, e.g. http.HTTPStatus(200) (#11318)" This reverts commit 34ae04f74dcf4ac97d07c3e82eaf8f619d80cedb. --- Lib/enum.py | 6 ++---- Misc/NEWS.d/next/Library/2018-12-26-02-28-00.bpo-35585.Lkzd3Z.rst | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) delete mode 100644 Misc/NEWS.d/next/Library/2018-12-26-02-28-00.bpo-35585.Lkzd3Z.rst diff --git a/Lib/enum.py b/Lib/enum.py index f7452f0cc0..fec1aed9b2 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -563,10 +563,8 @@ class Enum(metaclass=EnumMeta): # by-value search for a matching enum member # see if it's in the reverse mapping (for hashable values) try: - return cls._value2member_map_[value] - except KeyError: - # Not found, no need to do long O(n) search - pass + if value in cls._value2member_map_: + return cls._value2member_map_[value] except TypeError: # not there, now do long search -- O(n) behavior for member in cls._member_map_.values(): diff --git a/Misc/NEWS.d/next/Library/2018-12-26-02-28-00.bpo-35585.Lkzd3Z.rst b/Misc/NEWS.d/next/Library/2018-12-26-02-28-00.bpo-35585.Lkzd3Z.rst deleted file mode 100644 index 247a4ae680..0000000000 --- a/Misc/NEWS.d/next/Library/2018-12-26-02-28-00.bpo-35585.Lkzd3Z.rst +++ /dev/null @@ -1 +0,0 @@ -Speed-up building enums by value, e.g. http.HTTPStatus(200). -- cgit v1.2.1