classification
Title: Enum Flag: psuedo-members have None for name attribute
Type: enhancement Stage: needs patch
Components: Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
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 2020-09-26 10:29 by iritkatriel.

Messages (3)
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 triager) 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 triager) 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).
History
Date User Action Args
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