Skip to content

🐛 to_aiida_type: keep an enum member's class - #7647

Draft
GeigerJ2 wants to merge 1 commit into
aiidateam:mainfrom
GeigerJ2:fix/7646/to-aiida-type-enum
Draft

GeigerJ2 wants to merge 1 commit into
aiidateam:mainfrom
GeigerJ2:fix/7646/to-aiida-type-enum

Conversation

@GeigerJ2

Copy link
Copy Markdown
Collaborator

singledispatch resolves by method resolution order, and Enum is the one registered type meant to be mixed into another. A member of class Spin(str, Enum) is a str before it is an Enum, so the string won and the member was stored as a Str holding str(member), which reads, as '<enum>.<member>' and cannot be read back into the enum it came from. IntEnum and IntFlag kept the number and lost the class.

DISPATCH_PRECEDENCE names the registrations that outrank the rest of a value's resolution order, and to_aiida_type asks it before dispatching, so every member is stored as EnumData. Registering a conversion is unchanged, since register stays an attribute of the name that performs one.

@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.75%. Comparing base (0351256) to head (5e09938).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7647      +/-   ##
==========================================
+ Coverage   81.75%   81.75%   +0.01%     
==========================================
  Files         633      633              
  Lines       52731    52750      +19     
==========================================
+ Hits        43104    43123      +19     
  Misses       9627     9627              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@GeigerJ2
GeigerJ2 force-pushed the fix/7646/to-aiida-type-enum branch from b5aa4a6 to 5e09938 Compare September 16, 2026 11:52
`singledispatch` resolves by method resolution order, and `Enum` is the
one registered type meant to be mixed into another. A member of `class
Spin(str, Enum)` is a `str` before it is an `Enum`, so the string won
and the member was stored as a `Str` holding `str(member)`, which reads
as `'Spin.COLLINEAR'` and cannot be read back into the enum it came
from. `IntEnum` and `IntFlag` kept the number and lost the class.

`_DISPATCH_PRECEDENCE` names the classes asked ahead of whatever a value
inherits from outside them, and the public name resolves through it, so
every member is stored as `EnumData`. Precedence reorders the
resolution: a conversion registered for the enum itself is more specific
than the one for `Enum` and keeps its say.

`register`, `dispatch` and `registry` move onto the public name, which a
`Protocol` types so that `@to_aiida_type.register(...)` still checks, in
aiida-core and in every plugin that declares a conversion.
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