python-stdlib/enum: Add enum module #1061
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds enum package implementing PEP 435 (Enum) and PEP 663 (Flag) with modular lazy-loading structure.
This package provides CPython-compatible enum support for MicroPython, enabling libraries like python-statemachine and providing standard enum functionality for embedded projects.
Features
Complete enum implementation:
Structure
Modular design with lazy loading to minimize memory footprint:
Total size when frozen: ~5.4KB (core always loaded: ~1.7KB, features loaded on demand: ~950 bytes)
CPython Compatibility
Tested against CPython 3.13's official test_enum.py:
Works
Not Implemented
Enum('Name', 'A B C')- use class syntax insteadKnown Limitation
IntEnum members fail
isinstance(member, int)check in MicroPython due to implementation constraints, but all integer operations work correctly. This is a MicroPython limitation, not an enum package issue.MicroPython Requirements
Requires metaclass support from main MicroPython repo:
These features are included in the companion PR to micropython/micropython: #18416
Usage
Testing
Includes CPython's official test_enum.py (6000+ lines) for validation. Run on MicroPython Unix port:
Size Impact
When frozen into firmware:
Example for STM32 PYBV10:
Related
Companion PR for MicroPython core: micropython/micropython#18416