Commit 609b8aa
committed
enum: Add graceful error handling for auto() without __prepare__.
Previously, using auto() when MICROPY_PY_METACLASS_PREPARE was disabled
would silently create broken enum members with auto() objects as values
instead of integers.
Changes:
- Improved __prepare__ detection to actually test if it's called (not
just check if running on MicroPython)
- Added clear error message when auto() is used without __prepare__
support, guiding users to either enable the feature or use explicit
values
- All other enum features (Enum, IntEnum, Flag, IntFlag, StrEnum,
@unique) continue to work correctly without any C features
The error provides actionable guidance:
"auto() in enum Status.PENDING requires MICROPY_PY_METACLASS_PREPARE
to be enabled in py/mpconfig.h. Either enable this feature, or use
explicit integer values instead of auto()."
This prevents silent failures and provides better user experience on
minimal builds.
Signed-off-by: Andrew Leech <[email protected]>1 parent 1fb5654 commit 609b8aa
1 file changed
+32
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
19 | 36 | | |
20 | 37 | | |
21 | 38 | | |
| |||
120 | 137 | | |
121 | 138 | | |
122 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
123 | 149 | | |
124 | 150 | | |
125 | 151 | | |
| |||
0 commit comments