Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Checklist
- I am confident this is a bug in CPython, not a bug in a third-party project
- I have searched theCPython issue tracker,
and am confident this bug has not been reported before
CPython versions tested on:
3.11
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.11.5 (main, Aug 25 2023, 23:47:33) [GCC 12.2.0]
A clear and concise description of the bug:
A behavior ofFlag changed in python 3.11.5. WhenFlag with custom__new__ is used in combination with functional API, it's members can't be retrieved by iteration over the class.
MWE:
fromenumimportIntFlagPerm=IntFlag('Perm', {'R':4,'W':2,'X':1})print(tuple(Perm))classLabeledFlag(IntFlag):def__new__(cls,value:int,label:str):obj=super().__new__(cls,value)obj._value_=valueobj.label=labelreturnobjLabeledPerm=LabeledFlag('LabeledPerm', {'R': (4,'Read'),'W': (2,'Write'),'X': (1,'Exec')})print(tuple(LabeledPerm))
The output in python 3.11.4:
(<Perm.R: 4>, <Perm.W: 2>, <Perm.X: 1>)(<LabeledPerm.R: 4>, <LabeledPerm.W: 2>, <LabeledPerm.X: 1>)The output in python 3.11.5:
(<Perm.R: 4>, <Perm.W: 2>, <Perm.X: 1>)()I suspect this commit to introduce the regression:59f009e
A workaround for 3.11.5:
classLabeledFlag(IntFlag):def__new__(cls,value:int,label:str):obj=super().__new__(cls,value)obj._value_=valueobj.label=labelreturnobj@classmethoddef_missing_(cls,value):pseudo_member=super(_DnskeyFlagBase,cls)._missing_(value)ifvalueincls._value2member_map_andpseudo_member.nameisNone:cls._value2member_map_.pop(value)returnpseudo_member