diff options
author | Ethan Furman <ethan@stoneleaf.us> | 2022-11-15 16:49:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-15 16:49:22 (GMT) |
commit | 65dab1506e9c8ac40b3f9da834121d86c6417275 (patch) | |
tree | 4570072af1fdec50b105b1db974472eb71608920 /Lib/enum.py | |
parent | 3c57971a2d3b6d2c6fd1f525ba2108fccb35add2 (diff) | |
download | cpython-65dab1506e9c8ac40b3f9da834121d86c6417275.zip cpython-65dab1506e9c8ac40b3f9da834121d86c6417275.tar.gz cpython-65dab1506e9c8ac40b3f9da834121d86c6417275.tar.bz2 |
gh-92647: [Enum] use final status to determine lookup or create (GH-99500)
* use final status to determine lookup or create
* 📜🤖 Added by blurb_it.
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Diffstat (limited to 'Lib/enum.py')
-rw-r--r-- | Lib/enum.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Lib/enum.py b/Lib/enum.py index a04aa79..1b683c7 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -692,7 +692,7 @@ class EnumType(type): """ return True - def __call__(cls, value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None): + def __call__(cls, value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None): """ Either returns an existing member, or creates a new enum class. @@ -700,6 +700,8 @@ class EnumType(type): to an enumeration member (i.e. Color(3)) and for the functional API (i.e. Color = Enum('Color', names='RED GREEN BLUE')). + The value lookup branch is chosen if the enum is final. + When used for the functional API: `value` will be the name of the new class. @@ -717,12 +719,15 @@ class EnumType(type): `type`, if set, will be mixed in as the first base class. """ - if names is None: # simple value lookup + if cls._member_map_: + # simple value lookup if members exist + if names: + value = (value, names) + values return cls.__new__(cls, value) # otherwise, functional API: we're creating a new Enum type return cls._create_( - value, - names, + class_name=value, + names=names, module=module, qualname=qualname, type=type, |