You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The requirement that an enumerator name be all caps is not documented. While this is the style shown in the documentation of the standard enum library, it is not enforced. Removing the .isupper() checks resolves this issue. You might, however, want to substitute checks to see if an attribute is a callable method for the .isupper() calls.
The text was updated successfully, but these errors were encountered:
Sorry for the docs missing the notification about the requirement for ALL_CAPS for enums' members. We'll fix this ASAP.
As for the requirement itself it's just a way to avoid unresolveable cases while still following style guides. Look at the late-init example in the docs. Since we declare a non-member property halved_value that calculates to a member (different results for different members) we can't resolve this when not enforcing ALL_CAPS requirement for members.
Since then there's another issue with that: you can't declare non-members having ALL_CAPS names. They will be automatically treated as enums' members, but if and only if either check succedes:
it has a value assigned on declaration
it is type-hinted with the Enum class' name
This will avoid the mess:
In [102]: class Test(metaclass=FastEnum):
...: ONE: 'Test'
...: TWO: 'Test'
...: THREE: 'bytearray'
...: __slots__ = ('THREE', )
...: def __init_late(self):
...: self.THREE = bytearray(3)
...:
In [103]: list(Test)
Out[103]: [<Test.ONE: 1>, <Test.TWO: 2>]
In [104]: Test.ONE.THREE
Out[104]: bytearray(b'\x00\x00\x00')
In [105]: Test.ONE.THREE is Test.TWO.THREE
Out[105]: False
The requirement that an enumerator name be all caps is not documented. While this is the style shown in the documentation of the standard
enum
library, it is not enforced. Removing the.isupper()
checks resolves this issue. You might, however, want to substitute checks to see if an attribute is a callable method for the.isupper()
calls.The text was updated successfully, but these errors were encountered: