Skip to content

feat: an enum module - #280

Merged
jonruttan merged 1 commit into
mainfrom
feat/enum
Nov 29, 2026
Merged

jonruttan merged 1 commit into
mainfrom
feat/enum

Conversation

@jonruttan

Copy link
Copy Markdown
Owner

What

stdlib/enum.py, x-python's own enum, written to CPython 3.14's interface:

  • Enum, ReprEnum, IntEnum, StrEnum, Flag, IntFlag over an EnumType metaclass (EnumMeta alias) and EnumDict
  • auto(), member(), nonmember(), unique()
  • FlagBoundary with STRICT, CONFORM, EJECT, KEEP
  • The functional form, Enum('Animal', 'ANT BEE')
  • Aliases, _missing_, _order_, _ignore_, pseudo-members for flag combinations, and CPython's error messages

The README gets an enum row. It builds on #275 (metaclasses) and #277 (int-subclass arithmetic and class __get__).

Known differences

x-python runs a class body before its names reach the namespace __prepare__ returns. That causes two gaps, both noted in the module docstring:

  • A name given a value by auto() is still the auto object when the class body itself reads it. So AB = A | B works with explicit values only.
  • A name bound twice in the body keeps its last value; CPython refuses the second binding.

Also, __members__ is a dict copy rather than a mapping proxy.

Tests

tests/specs/D16-enum.spec.md has 6 cases. The expected output comes from CPython 3.14 with its own enum, and the same scripts give the same output with this module under CPython.

Locally, on the v0.65.0 pin:

  • D16: 6/6.
  • Full suite: 1314 tests, 0 failed. That's the 1308 baseline plus these 6.
  • Conformance at 450M objects: 644 tests, 3 failed. Same as main (array_int_repr, class_str, fun_code_colines).
  • if-ladders: none new.

🤖 Generated with Claude Code

stdlib/enum.py gives Enum, IntEnum, StrEnum, Flag and IntFlag over an
EnumType metaclass, with auto(), member(), nonmember(), unique(), the
FlagBoundary values and the functional form.  D16-enum checks it
against CPython 3.14's output.

Two gaps follow from x-python running a class body before its names
reach the prepared namespace: a name the body reads is still its
auto() object, and a name bound twice keeps its last value instead of
being refused.  __members__ is a dict copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonruttan
jonruttan merged commit 8f723f7 into main Nov 29, 2026
12 checks passed
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

Successfully merging this pull request may close these issues.

1 participant