Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requirement for enum name to be ALL_CAPS #1

Open
robbmcleod opened this issue Feb 11, 2020 · 2 comments · May be fixed by #2
Open

Requirement for enum name to be ALL_CAPS #1

robbmcleod opened this issue Feb 11, 2020 · 2 comments · May be fixed by #2
Assignees

Comments

@robbmcleod
Copy link

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.

@code-of-kpp
Copy link

Hi!
Currently this is sort of a hack to avoid expensive checks for key and name (and perhaps some other attributes).

@SantjagoCorkez
Copy link
Contributor

Hi, @robbmcleod

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

@SantjagoCorkez SantjagoCorkez self-assigned this Feb 14, 2020
@hiddify-com hiddify-com linked a pull request Feb 1, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants