@@ -1394,7 +1394,7 @@ symtable_exit_block(struct symtable *st)
13941394}
13951395
13961396static int
1397- symtable_enter_existing_block (struct symtable * st , PySTEntryObject * ste )
1397+ symtable_enter_existing_block (struct symtable * st , PySTEntryObject * ste , bool add_to_children )
13981398{
13991399 if (PyList_Append (st -> st_stack , (PyObject * )ste ) < 0 ) {
14001400 return 0 ;
@@ -1425,7 +1425,7 @@ symtable_enter_existing_block(struct symtable *st, PySTEntryObject* ste)
14251425 if (ste -> ste_type == ModuleBlock )
14261426 st -> st_global = st -> st_cur -> ste_symbols ;
14271427
1428- if (prev ) {
1428+ if (add_to_children && prev ) {
14291429 if (PyList_Append (prev -> ste_children , (PyObject * )ste ) < 0 ) {
14301430 return 0 ;
14311431 }
@@ -1440,7 +1440,7 @@ symtable_enter_block(struct symtable *st, identifier name, _Py_block_ty block,
14401440 PySTEntryObject * ste = ste_new (st , name , block , ast , loc );
14411441 if (ste == NULL )
14421442 return 0 ;
1443- int result = symtable_enter_existing_block (st , ste );
1443+ int result = symtable_enter_existing_block (st , ste , /* add_to_children */ true );
14441444 Py_DECREF (ste );
14451445 if (block == AnnotationBlock || block == TypeVariableBlock || block == TypeAliasBlock ) {
14461446 _Py_DECLARE_STR (format , ".format" );
@@ -1866,7 +1866,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
18661866 Py_DECREF (new_ste );
18671867 return 0 ;
18681868 }
1869- if (!symtable_enter_existing_block (st , new_ste )) {
1869+ if (!symtable_enter_existing_block (st , new_ste , /* add_to_children */ true )) {
18701870 Py_DECREF (new_ste );
18711871 return 0 ;
18721872 }
@@ -2223,7 +2223,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
22232223 Py_DECREF (new_ste );
22242224 return 0 ;
22252225 }
2226- if (!symtable_enter_existing_block (st , new_ste )) {
2226+ if (!symtable_enter_existing_block (st , new_ste , /* add_to_children */ true )) {
22272227 Py_DECREF (new_ste );
22282228 return 0 ;
22292229 }
@@ -2776,7 +2776,8 @@ symtable_visit_annotation(struct symtable *st, expr_ty annotation, void *key)
27762776 }
27772777 }
27782778 else {
2779- if (!symtable_enter_existing_block (st , parent_ste -> ste_annotation_block )) {
2779+ if (!symtable_enter_existing_block (st , parent_ste -> ste_annotation_block ,
2780+ /* add_to_children */ false)) {
27802781 return 0 ;
27812782 }
27822783 }
0 commit comments