Repository navigation
Conversation
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.
I am opening this PR to preserve the compiler's registration gates when reconstructing deferred class annotations. The code below currently loses the constant registration block when it is decompiled:
The first class entry is currently emitted as an unconditional annotation:
That preserves the visible value but changes how the class registers its annotations. In a class containing only constant-folded registration blocks, the unconditional output also loses the
__conditional_annotations__closure cell. In a mixed class, it changes the annotation function's guarded entries.Conditional class annotations are reconstructed from a deferred annotation function and registration markers. The change passes class-scope information into
p649_restore_gatesand retains a readableif Trueregistration block for class entries. Consecutive registration blocks are combined, while each field retains its compiler gate. The restoration recurses through conditionals, loops and handlers, preserving whether each annotation is registered and when its initializer runs.The retained wrappers preserve annotation registration and closure metadata but can introduce NOPs in the surrounding class code. Module entries retain their existing handling. Unreachable, unregistered entries remain omitted; the documented dead-branch STRING-format limitation remains.
The deferred evaluation and
__annotate__machinery addressed here begin in Python 3.14, as specified by PEP 649 and PEP 749.docs/LIMITATIONS.mdnow describes the preservation of live class registration gates.