classification
Title: Enum Flag: psuedo-members have None for name attribute
Type: enhancement Stage: resolved
Components: Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder: enum.Flag should be more set-like
View: 38250
Assigned To: ethan.furman Nosy List: ethan.furman, fbidu, iritkatriel, rahul-kumi
Priority: normal Keywords:

Created on 2020-03-22 12:45 by ethan.furman, last changed 2021-02-01 20:13 by ethan.furman. This issue is now closed.

Messages (4)
msg369223 - (view) Author: Felipe Rodrigues (fbidu) * Date: 2020-05-18 14:05
Hi,

Can you elaborate on this?

Thanks!
msg377426 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-09-23 21:36
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"
msg377521 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-09-26 10:29
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).
msg386102 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2021-02-01 20:13
This issue is fixed in #38250.
History
Date User Action Args
2021-02-01 20:13:25ethan.furmansetstatus: open -> closed
superseder: enum.Flag should be more set-like
messages: + msg386102

resolution: fixed
stage: needs patch -> resolved
2020-09-26 10:29:14iritkatrielsetmessages: + msg377521
2020-09-23 21:36:56iritkatrielsetnosy: + iritkatriel
messages: + msg377426
2020-05-18 16:40:45rahul-kumisetnosy: + rahul-kumi
2020-05-18 14:05:38fbidusetnosy: + fbidu
messages: + msg369223
2020-03-22 12:45:55ethan.furmansettype: enhancement
2020-03-22 12:45:27ethan.furmancreate