classification
Title: Cannot use functional API to create enum with zero values
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ethan.furman Nosy List: Gerrit.Holl, ethan.furman, vstinner
Priority: low Keywords:

Created on 2017-06-09 17:30 by Gerrit.Holl, last changed 2017-08-17 08:57 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 2304 merged corona10, 2017-06-20 16:17
PR 2324 merged corona10, 2017-06-22 03:04
PR 2888 closed corona10, 2017-07-26 06:40
PR 2889 closed corona10, 2017-07-26 07:03
Messages (5)
msg295559 - (view) Author: Gerrit Holl (Gerrit.Holl) * Date: 2017-06-09 17:30
The OO API allows to create empty enums, i.e. without any values.  However, the functional API does not, as this will result in an IndexError as shown below:

In [1]: import enum

In [2]: class X(enum.IntFlag): pass

In [3]: Y = enum.IntFlag("Y", [])
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-3-1fda5945e0b2> in <module>()
----> 1 Y = enum.IntFlag("Y", [])

~/lib/python3.6/enum.py in __call__(cls, value, names, module, qualname, type, start)
    291             return cls.__new__(cls, value)
    292         # otherwise, functional API: we're creating a new Enum type
--> 293         return cls._create_(value, names, module=module, qualname=qualname, type=type, start=start)
    294 
    295     def __contains__(cls, member):

~/lib/python3.6/enum.py in _create_(cls, class_name, names, module, qualname, type, start)
    382         if isinstance(names, str):
    383             names = names.replace(',', ' ').split()
--> 384         if isinstance(names, (tuple, list)) and isinstance(names[0], str):
    385             original_names, names = names, []
    386             last_values = []

IndexError: list index out of range
msg296567 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2017-06-21 16:52
New changeset dcc8ce44c74492670e6bfbde588a2acbf8f365e0 by ethanfurman (Dong-hee Na) in branch 'master':
bpo-30616: Functional API of enum allows to create empty enums. (#2304)
https://github.com/python/cpython/commit/dcc8ce44c74492670e6bfbde588a2acbf8f365e0
msg296569 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2017-06-21 16:58
3.7 fixed, now need 3.6.
msg296776 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2017-06-24 16:12
New changeset 504b95047a8ada06ab630abce55ac2f85566ca37 by ethanfurman (Dong-hee Na) in branch '3.6':
[3.6] bpo-30616: Functional API of enum allows to create empty enums. (#2304) (#2324)
https://github.com/python/cpython/commit/504b95047a8ada06ab630abce55ac2f85566ca37
msg300404 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-08-17 08:57
Thanks for the bugreport Gerrit Holl and thanks for fixes Dong-hee Na!
History
Date User Action Args
2017-08-17 08:57:32vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg300404

resolution: fixed
stage: backport needed -> resolved
2017-07-26 07:03:38corona10setpull_requests: + pull_request2941
2017-07-26 06:40:07corona10setpull_requests: + pull_request2940
2017-06-24 16:12:22ethan.furmansetmessages: + msg296776
2017-06-22 03:04:38corona10setpull_requests: + pull_request2373
2017-06-21 16:58:43ethan.furmansetmessages: + msg296569
stage: test needed -> backport needed
2017-06-21 16:52:35ethan.furmansetmessages: + msg296567
2017-06-20 16:17:35corona10setpull_requests: + pull_request2351
2017-06-09 17:58:23ethan.furmansetpriority: normal -> low
assignee: ethan.furman
stage: test needed
components: + Library (Lib)
versions: + Python 3.7
2017-06-09 17:55:54ethan.furmansetnosy: + ethan.furman
2017-06-09 17:30:17Gerrit.Hollcreate