Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use functional API to create enum with zero values #74801

Closed
gerritholl mannequin opened this issue Jun 9, 2017 · 5 comments
Closed

Cannot use functional API to create enum with zero values #74801

gerritholl mannequin opened this issue Jun 9, 2017 · 5 comments
Assignees
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir

Comments

@gerritholl
Copy link
Mannequin

gerritholl mannequin commented Jun 9, 2017

BPO 30616
Nosy @vstinner, @ethanfurman, @gerritholl
PRs
  • bpo-30616: Functional API of enum allows to create empty enums. #2304
  • [3.6] bpo-30616: Functional API of enum allows to create empty enums (#2304) #2324
  • [3.5] bpo-30616: Functional API of enum allows to create empty enums (#2304) #2888
  • [3.5] bpo-30616: Functional API of enum allows to create empty enums (#2304) #2889
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/ethanfurman'
    closed_at = <Date 2017-08-17.08:57:32.952>
    created_at = <Date 2017-06-09.17:30:17.874>
    labels = ['3.7', 'library']
    title = 'Cannot use functional API to create enum with zero values'
    updated_at = <Date 2017-08-17.08:57:32.934>
    user = 'https://github.com/gerritholl'

    bugs.python.org fields:

    activity = <Date 2017-08-17.08:57:32.934>
    actor = 'vstinner'
    assignee = 'ethan.furman'
    closed = True
    closed_date = <Date 2017-08-17.08:57:32.952>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2017-06-09.17:30:17.874>
    creator = 'Gerrit.Holl'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30616
    keywords = []
    message_count = 5.0
    messages = ['295559', '296567', '296569', '296776', '300404']
    nosy_count = 3.0
    nosy_names = ['vstinner', 'ethan.furman', 'Gerrit.Holl']
    pr_nums = ['2304', '2324', '2888', '2889']
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue30616'
    versions = ['Python 3.6', 'Python 3.7']

    @gerritholl
    Copy link
    Mannequin Author

    gerritholl mannequin commented Jun 9, 2017

    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

    @ethanfurman ethanfurman added 3.7 (EOL) end of life stdlib Python modules in the Lib dir labels Jun 9, 2017
    @ethanfurman ethanfurman self-assigned this Jun 9, 2017
    @ethanfurman
    Copy link
    Member

    New changeset dcc8ce4 by ethanfurman (Dong-hee Na) in branch 'master':
    bpo-30616: Functional API of enum allows to create empty enums. (bpo-2304)
    dcc8ce4

    @ethanfurman
    Copy link
    Member

    3.7 fixed, now need 3.6.

    @ethanfurman
    Copy link
    Member

    New changeset 504b950 by ethanfurman (Dong-hee Na) in branch '3.6':
    [3.6] bpo-30616: Functional API of enum allows to create empty enums. (bpo-2304) (bpo-2324)
    504b950

    @vstinner
    Copy link
    Member

    Thanks for the bugreport Gerrit Holl and thanks for fixes Dong-hee Na!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants