Skip to content

Enum Flag: psuedo-members have None for name attribute #84223

Closed

Description

@ethanfurman
BPO 40042
Nosy @ethanfurman, @fbidu, @rahul-kumi, @iritkatriel
Superseder
  • bpo-38250: enum.Flag should be more set-like
  • 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 2021-02-01.20:13:25.010>
    created_at = <Date 2020-03-22.12:45:27.948>
    labels = ['type-feature', '3.9']
    title = 'Enum Flag: psuedo-members have None for name attribute'
    updated_at = <Date 2021-02-01.20:13:25.010>
    user = 'https://github.com/ethanfurman'

    bugs.python.org fields:

    activity = <Date 2021-02-01.20:13:25.010>
    actor = 'ethan.furman'
    assignee = 'ethan.furman'
    closed = True
    closed_date = <Date 2021-02-01.20:13:25.010>
    closer = 'ethan.furman'
    components = []
    creation = <Date 2020-03-22.12:45:27.948>
    creator = 'ethan.furman'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40042
    keywords = []
    message_count = 4.0
    messages = ['369223', '377426', '377521', '386102']
    nosy_count = 4.0
    nosy_names = ['ethan.furman', 'fbidu', 'rahul-kumi', 'iritkatriel']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = '38250'
    type = 'enhancement'
    url = 'https://bugs.python.org/issue40042'
    versions = ['Python 3.9']

    Activity

    1. self-assigned this
      on Mar 22, 2020
    2. self-assigned this
      on Mar 22, 2020
    3. fbidu commented on May 18, 2020

      fbidumannequin
      Mannequin

      Hi,

      Can you elaborate on this?

      Thanks!

    4. iritkatriel commented on Sep 23, 2020

      @iritkatriel
      Member

      I believe this is what Rahul means:

      import enum
      class Color(enum.Flag):
          RED = enum.auto()
          BLUE = enum.auto()
          GREEN = enum.auto()
      
      white = Color.RED | Color.BLUE | Color.GREEN
      assert white.name is None

      # Note, however that:
      assert str(Color.RED | Color.BLUE | Color.GREEN) == "Color.GREEN|BLUE|RED"

    5. iritkatriel commented on Sep 26, 2020

      @iritkatriel
      Member

      I see in the code of _create_pseudo_member_ that _name_ is deliberately set to None, and furthermore in __str__ and __repr__ the fact that it is None is used to determine whether self is a composite (pseudo) or not.

      So first question is whether this should be fixed.

      If so, I see two options:

      1. Establish another way to determine whether self is a composite or not, and change they way _name_ is initialised.

      2. Leave _name_ as is, but override name (which currently is defined in Enum and simply returns _name_ but can be redefined to do something else).

    6. ethanfurman commented on Feb 1, 2021

      @ethanfurman
      MemberAuthor

      This issue is fixed in bpo-38250.

    7. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    3.9 (EOL)end of lifetype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions