Skip to content

Fix enum construction after registering an enum named type - #1612

Open
Rajatendu1 wants to merge 1 commit into
graphql-python:masterfrom
Rajatendu1:fix/enum-type-builtin
Open

Rajatendu1 wants to merge 1 commit into
graphql-python:masterfrom
Rajatendu1:fix/enum-type-builtin

Conversation

@Rajatendu1

Copy link
Copy Markdown

Fixes #1519.

The original report identified that EnumMeta registers generated enums in module globals for pickling. An enum called type then shadows Python's builtin and breaks subsequent enum construction.

This patch follows the reporter's suggested builtins.type approach at the two class-construction sites in EnumMeta.from_enum. It leaves the pickling registration unchanged. Three tests cover class syntax, functional construction and conversion from a Python enum, each followed by constructing another enum. The tests restore the module global afterward.

Validation:

  • Clean unmodified Python 3.12 suite: 465 passed. Final patched suite: 468 passed.
  • All three new tests fail on unpatched source and pass with the fix.
  • Python 3.10 and 3.13: 468 passed each.
  • Python 3.12 project coverage run, including benchmarks: 468 passed, 96% aggregate coverage with the project's exclusions.
  • Full mypy, Ruff check/format and diff check pass. Existing enum-pickling regression passes.

These are local Linux results. Benchmark timing was disabled for the clean baseline, final recheck and Python 3.10/3.13 suites; Python 3.8/3.9/3.11 and other operating systems were not tested. The fix is limited to the reported type collision, not a redesign of the module-global enum registry.

AI assistance was used to prepare this patch, tests and description. The original diagnosis and suggested use of builtins.type are credited to the report in #1519 and its linked reproduction repository.

This branch has not been deployed

No deployments
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.

Enum conversion to Graphene Enum fails if Enum name is "type"

1 participant