Issue 34487: enum sunder names mix metaclass and enum class attributes (original) (raw)

In the enum module documentation, some of the _sunder_ names are on EnumMeta, whereas others are on the produced Enum class:

8.13.15.3.2. Supported _sunder_ names

Experimentally, it appears _name_ and _value_ are on the Enum class, whereas the others are all on the EnumMeta class:

In [272]: class Test(enum.Enum): a = 0

In [273]: Test.a.name Out[273]: 'a'

In [274]: Test._name

AttributeError Traceback (most recent call last) in () ----> 1 Test._name

/group_workspaces/cems2/fiduceo/Users/gholl/anaconda3/envs/FCDR37a/lib/python3.7/enum.py in getattr(cls, name) 344 return cls.member_map[name] 345 except KeyError: --> 346 raise AttributeError(name) from None 347 348 def getitem(cls, name):

AttributeError: _name

In [275]: Test.a.value Out[275]: 0

In [276]: Test._value

AttributeError Traceback (most recent call last) in () ----> 1 Test._value

/group_workspaces/cems2/fiduceo/Users/gholl/anaconda3/envs/FCDR37a/lib/python3.7/enum.py in getattr(cls, name) 344 return cls.member_map[name] 345 except KeyError: --> 346 raise AttributeError(name) from None 347 348 def getitem(cls, name):

AttributeError: _value

In [277]: Test.a.missing Out[277]: <bound method Enum._missing_ of <enum 'Test'>>

In [278]: Test.missing Out[278]: <bound method Enum._missing_ of <enum 'Test'>>

This is not clear from the documentation.