@@ -734,29 +734,9 @@ codegen_leave_annotations_scope(compiler *c, location loc)
734734}
735735
736736static int
737- codegen_process_deferred_annotations (compiler * c , location loc )
737+ codegen_deferred_annotations_body (compiler * c , location loc ,
738+ PyObject * deferred_anno , PyObject * conditional_annotation_indices , int scope_type )
738739{
739- PyObject * deferred_anno = NULL ;
740- PyObject * conditional_annotation_indices = NULL ;
741- _PyCompile_DeferredAnnotations (c , & deferred_anno , & conditional_annotation_indices );
742- if (deferred_anno == NULL ) {
743- assert (conditional_annotation_indices == NULL );
744- return SUCCESS ;
745- }
746-
747- // It's possible that ste_annotations_block is set but
748- // u_deferred_annotations is not, because the former is still
749- // set if there are only non-simple annotations (i.e., annotations
750- // for attributes, subscripts, or parenthesized names). However, the
751- // reverse should not be possible.
752- PySTEntryObject * ste = SYMTABLE_ENTRY (c );
753- assert (ste -> ste_annotation_block != NULL );
754- void * key = (void * )((uintptr_t )ste -> ste_id + 1 );
755- int scope_type = SCOPE_TYPE (c );
756- if (codegen_setup_annotations_scope (c , loc , key ,
757- ste -> ste_annotation_block -> ste_name ) < 0 ) {
758- goto error ;
759- }
760740 Py_ssize_t annotations_len = PyList_Size (deferred_anno );
761741
762742 assert (PyList_CheckExact (conditional_annotation_indices ));
@@ -768,13 +748,11 @@ codegen_process_deferred_annotations(compiler *c, location loc)
768748 PyObject * ptr = PyList_GET_ITEM (deferred_anno , i );
769749 stmt_ty st = (stmt_ty )PyLong_AsVoidPtr (ptr );
770750 if (st == NULL ) {
771- _PyCompile_ExitScope (c );
772- goto error ;
751+ return ERROR ;
773752 }
774753 PyObject * mangled = _PyCompile_Mangle (c , st -> v .AnnAssign .target -> v .Name .id );
775754 if (!mangled ) {
776- _PyCompile_ExitScope (c );
777- goto error ;
755+ return ERROR ;
778756 }
779757 PyObject * cond_index = PyList_GET_ITEM (conditional_annotation_indices , i );
780758 assert (PyLong_CheckExact (cond_index ));
@@ -805,6 +783,39 @@ codegen_process_deferred_annotations(compiler *c, location loc)
805783
806784 USE_LABEL (c , not_set );
807785 }
786+ return SUCCESS ;
787+ }
788+
789+ static int
790+ codegen_process_deferred_annotations (compiler * c , location loc )
791+ {
792+ PyObject * deferred_anno = NULL ;
793+ PyObject * conditional_annotation_indices = NULL ;
794+ _PyCompile_DeferredAnnotations (c , & deferred_anno , & conditional_annotation_indices );
795+ if (deferred_anno == NULL ) {
796+ assert (conditional_annotation_indices == NULL );
797+ return SUCCESS ;
798+ }
799+
800+ // It's possible that ste_annotations_block is set but
801+ // u_deferred_annotations is not, because the former is still
802+ // set if there are only non-simple annotations (i.e., annotations
803+ // for attributes, subscripts, or parenthesized names). However, the
804+ // reverse should not be possible.
805+ PySTEntryObject * ste = SYMTABLE_ENTRY (c );
806+ assert (ste -> ste_annotation_block != NULL );
807+ void * key = (void * )((uintptr_t )ste -> ste_id + 1 );
808+ int scope_type = SCOPE_TYPE (c );
809+ if (codegen_setup_annotations_scope (c , loc , key ,
810+ ste -> ste_annotation_block -> ste_name ) < 0 ) {
811+ goto error ;
812+ }
813+ if (codegen_deferred_annotations_body (c , loc , deferred_anno ,
814+ conditional_annotation_indices , scope_type ) < 0 ) {
815+ _PyCompile_ExitScope (c );
816+ goto error ;
817+ }
818+
808819 Py_DECREF (deferred_anno );
809820 Py_DECREF (conditional_annotation_indices );
810821
0 commit comments