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
Enums are especially useful when it comes to static type-checking. So it would be great if the implementation of this enum type allowed type-checking via mypy. This means all values need to be an instance of the defined enum-type.
>>> class MyEnum(enum.IntEnum):
... A = 1
... B = 2
>>> isinstance(MyEnum.A, MyEnum)
True
As such any micropython implementation will need to be completely custom really, at which point we need to clearly define which aspects of Enum we want to support first, before figuring out how to implement them!
Activity
stlehmann commentedon Apr 4, 2018
Enums are especially useful when it comes to static type-checking. So it would be great if the implementation of this enum type allowed type-checking via mypy. This means all values need to be an instance of the defined enum-type.
njourdane commentedon Feb 20, 2022
I'm also interested by enum in MicroPython.
In the meantime, I found here this workaround:
matejcik commentedon Feb 20, 2022
for type-checking, I'm using the following trick:
brotherdust commentedon Oct 14, 2022
This workaround is excellent! I combined it with const for my purposes:
esologic commentedon Dec 11, 2022
+1 for a real implementation of this
i33l commentedon May 26, 2023
But when have been imported getting "Unresolved attribute reference" warning.
andrewleech commentedon May 26, 2023
The cpython implementation is surprisingly very complicated and relies heavily on metaclasses which aren't supported in micropython:
https://github.com/python/cpython/blob/f585ed19ad00f78ed99ba44be5e333c056076160/Lib/enum.py#L1051
As such any micropython implementation will need to be completely custom really, at which point we need to clearly define which aspects of Enum we want to support first, before figuring out how to implement them!
andrewleech commentedon May 26, 2023
There are a number of limitations when subclassing builtins in micropython, especially
int
because behind the scenes it's particularly optimised. Eg. https://docs.micropython.org/en/latest/genrst/builtin_types.html#no-int-conversion-for-int-derived-types-availablebredbord commentedon Mar 7, 2024
+1 for an implementation of this as well.
IhorNehrutsa commentedon Mar 1, 2025
docs/library/enum.rst: Add Enum class. #16842
IhorNehrutsa commentedon Mar 5, 2025
Implementation in:
micropython-lib/python-stdlib/enum/enum.py: Add Enum class. #980
1 remaining item