@@ -722,17 +722,6 @@ _PyCompile_EnterScope(compiler *c, identifier name, int scope_type,
722722 return ERROR ;
723723 }
724724 }
725- if (u -> u_ste -> ste_has_conditional_annotations ) {
726- /* Cook up an implicit __conditional_annotations__ cell */
727- Py_ssize_t res ;
728- assert (u -> u_scope_type == COMPILE_SCOPE_CLASS || u -> u_scope_type == COMPILE_SCOPE_MODULE );
729- res = _PyCompile_DictAddObj (u -> u_metadata .u_cellvars , & _Py_ID (__conditional_annotations__ ));
730- if (res < 0 ) {
731- compiler_unit_free (u );
732- return ERROR ;
733- }
734- }
735-
736725 u -> u_metadata .u_freevars = dictbytype (u -> u_ste -> ste_symbols , FREE , DEF_FREE_CLASS ,
737726 PyDict_GET_SIZE (u -> u_metadata .u_cellvars ));
738727 if (!u -> u_metadata .u_freevars ) {
@@ -1001,6 +990,15 @@ compiler_resolve_inlined_free(PySTEntryObject **ste, PyObject *name)
1001990 assert (parent != NULL );
1002991 if (parent -> ste_type == ClassBlock ) {
1003992 if (_PyST_IsClassClosureName (name )) {
993+ /* __conditional_annotations__ is a real CELL on the class;
994+ * other class-closure names (__class__, ...) are cooked
995+ * under private cellvar names and are not in ste_symbols. */
996+ int parent_scope = _PyST_GetScope (parent , name );
997+ RETURN_IF_ERROR (parent_scope );
998+ if (parent_scope == CELL ) {
999+ * ste = parent ;
1000+ return CELL ;
1001+ }
10041002 return GLOBAL_IMPLICIT ;
10051003 }
10061004 break ;
@@ -1024,24 +1022,12 @@ compiler_class_closure_cellvar(PyObject *name)
10241022 if (name == & _Py_ID (__classdict__ )) {
10251023 return & _Py_ID (__classdictcell__ );
10261024 }
1027- if (name == & _Py_ID (__conditional_annotations__ )) {
1028- return & _Py_ID (__conditional_annotations__ );
1029- }
10301025 return NULL ;
10311026}
10321027
10331028int
10341029_PyCompile_GetRefType (compiler * c , PyObject * name )
10351030{
1036- /* Synthetic cells cooked into u_cellvars under their public spelling
1037- * (today only __conditional_annotations__) are not always in ste_symbols. */
1038- if (c -> u -> u_scope_type == COMPILE_SCOPE_CLASS ||
1039- c -> u -> u_scope_type == COMPILE_SCOPE_MODULE ) {
1040- PyObject * cell_name = compiler_class_closure_cellvar (name );
1041- if (cell_name != NULL && cell_name == name ) {
1042- return CELL ;
1043- }
1044- }
10451031 PySTEntryObject * ste = c -> u -> u_ste ;
10461032 int scope = compiler_resolve_inlined_free (& ste , name );
10471033 RETURN_IF_ERROR (scope );
@@ -1081,9 +1067,9 @@ int
10811067_PyCompile_LookupArg (compiler * c , PyCodeObject * co , PyObject * name )
10821068{
10831069 /* Class units store the synthetic class-closure cell under a private
1084- * name (__classcell__, ...). Inside an inlined comprehension, a nested
1085- * free of the public name usually captures that comprehension's CELL;
1086- * elsewhere (methods, class-body lambdas) it is the private cell . */
1070+ * name (__classcell__, ...). Map a free of the public name to that
1071+ * private cell, except in an inlined comprehension that already has
1072+ * its own CELL under the public name — prefer that slot . */
10871073 if (c -> u -> u_scope_type == COMPILE_SCOPE_CLASS ) {
10881074 PyObject * cell_name = compiler_class_closure_cellvar (name );
10891075 if (cell_name != NULL ) {
0 commit comments