@@ -788,7 +788,7 @@ codegen_deferred_annotations_body(compiler *c, location loc,
788788 ADDOP_I (c , LOC (st ), COPY , 2 );
789789 ADDOP_LOAD_CONST_NEW (c , LOC (st ), mangled );
790790 // stack now contains <annos> <name> <annos> <value>
791- ADDOP (c , loc , STORE_SUBSCR );
791+ ADDOP (c , LOC ( st ) , STORE_SUBSCR );
792792 // stack now contains <annos>
793793
794794 USE_LABEL (c , not_set );
@@ -823,7 +823,14 @@ codegen_process_deferred_annotations(compiler *c, location loc)
823823 PySTEntryObject * ste = SYMTABLE_ENTRY (c );
824824 assert (ste -> ste_annotation_block != NULL );
825825 void * key = (void * )((uintptr_t )ste -> ste_id + 1 );
826- if (codegen_setup_annotations_scope (c , loc , key ,
826+
827+ // Get the first annotation location
828+ PyObject * ptr = PyList_GET_ITEM (deferred_anno , 0 );
829+ stmt_ty st = (stmt_ty )PyLong_AsVoidPtr (ptr );
830+ if (st == NULL ) {
831+ goto error ;
832+ }
833+ if (codegen_setup_annotations_scope (c , LOC (st ), key ,
827834 ste -> ste_annotation_block -> ste_name ) < 0 ) {
828835 goto error ;
829836 }
@@ -836,12 +843,11 @@ codegen_process_deferred_annotations(compiler *c, location loc)
836843 Py_DECREF (deferred_anno );
837844 Py_DECREF (conditional_annotation_indices );
838845
839- RETURN_IF_ERROR (codegen_leave_annotations_scope (c , loc ));
846+ RETURN_IF_ERROR (codegen_leave_annotations_scope (c , LOC ( st ) ));
840847 RETURN_IF_ERROR (codegen_nameop (
841- c , loc ,
848+ c , LOC ( st ) ,
842849 ste -> ste_type == ClassBlock ? & _Py_ID (__annotate_func__ ) : & _Py_ID (__annotate__ ),
843850 Store ));
844-
845851 if (need_separate_block ) {
846852 RETURN_IF_ERROR (_PyCompile_EndAnnotationSetup (c ));
847853 }
868874_PyCodegen_Module (compiler * c , location loc , asdl_stmt_seq * stmts , bool is_interactive )
869875{
870876 if (SYMTABLE_ENTRY (c )-> ste_has_conditional_annotations ) {
871- ADDOP_I (c , loc , BUILD_SET , 0 );
872- ADDOP_N (c , loc , STORE_NAME , & _Py_ID (__conditional_annotations__ ), names );
877+ ADDOP_I (c , NO_LOCATION , BUILD_SET , 0 );
878+ ADDOP_N (c , NO_LOCATION , STORE_NAME , & _Py_ID (__conditional_annotations__ ), names );
873879 }
874880 return codegen_body (c , loc , stmts , is_interactive );
875881}
@@ -1562,8 +1568,8 @@ codegen_class_body(compiler *c, stmt_ty s, int firstlineno)
15621568 ADDOP_N_IN_SCOPE (c , loc , STORE_DEREF , & _Py_ID (__classdict__ ), cellvars );
15631569 }
15641570 if (SYMTABLE_ENTRY (c )-> ste_has_conditional_annotations ) {
1565- ADDOP_I (c , loc , BUILD_SET , 0 );
1566- ADDOP_N_IN_SCOPE (c , loc , STORE_DEREF , & _Py_ID (__conditional_annotations__ ), cellvars );
1571+ ADDOP_I (c , NO_LOCATION , BUILD_SET , 0 );
1572+ ADDOP_N_IN_SCOPE (c , NO_LOCATION , STORE_DEREF , & _Py_ID (__conditional_annotations__ ), cellvars );
15671573 }
15681574 /* compile the body proper */
15691575 RETURN_IF_ERROR_IN_SCOPE (c , codegen_body (c , loc , s -> v .ClassDef .body , false));
0 commit comments