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

Python <3.11 does not have the enum.EnumType metaclass #3

Open
stefanches7 opened this issue Sep 3, 2024 · 7 comments
Open

Python <3.11 does not have the enum.EnumType metaclass #3

stefanches7 opened this issue Sep 3, 2024 · 7 comments

Comments

@stefanches7
Copy link

Evidence: https://docs.python.org/3.10/library/enum.html#data-types vs. https://docs.python.org/3.11/library/enum.html#data-types

Ran on Python 3.10:
image

Running in the same environment with Python 3.12 solves this.

@stefanches7
Copy link
Author

One could add it to the environment.yml and for the pip users either in a README or something in the flavor of https://stackoverflow.com/a/68987487

@stefanches7 stefanches7 changed the title Python <3.11 does not have enum.EnumType metaclass Python <3.11 does not have the enum.EnumType metaclass Sep 4, 2024
@stefanches7
Copy link
Author

@joshmoore

@joshmoore
Copy link
Owner

Doh! Thanks, @stefanches7. I'd be for supporting 3.10+ but we'll need to do something a bit smarter here. Do you know off-hand?

@stefanches7
Copy link
Author

I was thinking in the direction of inherting from Enum: https://docs.python.org/3/library/functions.html#issubclass
Would it theoretically work? I might then open a PR @joshmoore

@joshmoore
Copy link
Owner

Off-hand it sounds fine.

@stefanches7
Copy link
Author

Tested locally. My educated guess is that the metaclasses have a different class structure interface.
I did not check how does it work for python < 3.10, because obviously this won't be compatible with the most recent Python versions (>3.11) @joshmoore
image

@joshmoore
Copy link
Owner

One possibility maybe is to just use isinstance:

>>> import enum
>>> class Color(enum.Enum):
...     A=1
...
>>> Color.A
<Color.A: 1>
>>> isinstance(Color.A, enum.Enum)
True

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

No branches or pull requests

2 participants