Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
GeigerJ2
force-pushed
the
fix/7646/to-aiida-type-enum
branch
from
September 16, 2026 11:52
b5aa4a6 to
5e09938
Compare
`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.
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
Sign up for free
to 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.
singledispatchresolves by method resolution order, andEnumis the one registered type meant to be mixed into another. A member ofclass Spin(str, Enum)is astrbefore it is anEnum, so the string won and the member was stored as aStrholdingstr(member), which reads, as'<enum>.<member>'and cannot be read back into the enum it came from.IntEnumandIntFlagkept the number and lost the class.DISPATCH_PRECEDENCEnames the registrations that outrank the rest of a value's resolution order, andto_aiida_typeasks it before dispatching, so every member is stored asEnumData. Registering a conversion is unchanged, sinceregisterstays an attribute of the name that performs one.