Repository navigation
Conversation
When a class body binds __classdict__ (assignment, for target, global, del), analyze_name() treated the name as global in the annotation and type parameter scopes that can see the class, so they no longer got the __classdict__ cell the class creates for them. Compiling such a class with a generic class inside crashed, and with an annotated method or a type alias raised SystemError. Skip that rule for __classdict__ itself.
|
The following commit authors need to sign the Contributor License Agreement: |
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.
When a class body binds
__classdict__(assignment,fortarget,delorglobal),analyze_name()inPython/symtable.capplied the rule for names bound in the enclosing class to__classdict__as well. Annotation and type parameter scopes inside the class then treated it as a global instead of a free variable, so they lost the__classdict__cell the class creates for them. Compiling a generic class in such a class body hit theassemble.cassertion (segfault in a release build); an annotated method, a generic function or atypealias raisedSystemError.The change skips that rule for
__classdict__only, so these scopes always use the cell. Other names bound in the class keep the current behaviour.Tests: new
DeferredEvaluationTests.test_class_binds_dunder_classdictintest_type_annotationscovers assignment, annotated assignment,forandglobal, and checks that annotations, type parameter bounds and the alias value still resolve against the class namespace. Debug build of current main (ab48ba8edf) on macOS arm64: without thesymtable.cchange the new test fails withSystemErrorand the reproducer from the issue aborts on the assertion; with it both pass.test_type_annotations,test_type_params,test_symtable,test_compile,test_annotationlib,test_grammar,test_syntax,test_scope,test_typing,test_dis,test_ast,test_inspect,test_builtin,test_funcattrs,test_descr,test_superandtest_classpass, andtest_type_annotations -R 3:3reports no leaks.This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.
__classdict__and contains a generic class #161849