- Notifications
You must be signed in to change notification settings - Fork1.1k
python-stdlib/enum: Add enum module#1061
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Draft
andrewleech wants to merge1 commit intomicropython:masterChoose a base branch fromandrewleech:add-enum-package
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Draft
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Implements PEP 435 (Enum) and PEP 663 (Flag) with modular structure:- Enum, IntEnum with member management and value lookup- Flag, IntFlag with bitwise operations and combination membership- StrEnum for string-valued enums (Python 3.11+)- auto() for automatic value assignment-@unique decorator for duplicate value preventionUses lazy loading to minimize memory footprint (~1.5KB core, ~2.5KBwhen all features loaded).Requires metaclass support:* MICROPY_PY_METACLASS_INIT for basic enums.* MICROPY_PY_METACLASS_PREPARE for auto() support.99.3% compatible with CPython 3.13 enum test suite (445/448 tests pass).Includes CPython's official test_enum.py for validation.Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
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