@@ -141,6 +141,7 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
141
141
ste -> ste_needs_classdict = 0 ;
142
142
ste -> ste_has_conditional_annotations = 0 ;
143
143
ste -> ste_in_conditional_block = 0 ;
144
+ ste -> ste_in_unevaluated_annotation = 0 ;
144
145
ste -> ste_annotation_block = NULL ;
145
146
146
147
ste -> ste_has_docstring = 0 ;
@@ -2538,17 +2539,19 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
2538
2539
VISIT (st , expr , e -> v .Slice .step );
2539
2540
break ;
2540
2541
case Name_kind :
2541
- if (!symtable_add_def_ctx (st , e -> v .Name .id ,
2542
- e -> v .Name .ctx == Load ? USE : DEF_LOCAL ,
2543
- LOCATION (e ), e -> v .Name .ctx )) {
2544
- return 0 ;
2545
- }
2546
- /* Special-case super: it counts as a use of __class__ */
2547
- if (e -> v .Name .ctx == Load &&
2548
- _PyST_IsFunctionLike (st -> st_cur ) &&
2549
- _PyUnicode_EqualToASCIIString (e -> v .Name .id , "super" )) {
2550
- if (!symtable_add_def (st , & _Py_ID (__class__ ), USE , LOCATION (e )))
2542
+ if (!st -> st_cur -> ste_in_unevaluated_annotation ) {
2543
+ if (!symtable_add_def_ctx (st , e -> v .Name .id ,
2544
+ e -> v .Name .ctx == Load ? USE : DEF_LOCAL ,
2545
+ LOCATION (e ), e -> v .Name .ctx )) {
2551
2546
return 0 ;
2547
+ }
2548
+ /* Special-case super: it counts as a use of __class__ */
2549
+ if (e -> v .Name .ctx == Load &&
2550
+ _PyST_IsFunctionLike (st -> st_cur ) &&
2551
+ _PyUnicode_EqualToASCIIString (e -> v .Name .id , "super" )) {
2552
+ if (!symtable_add_def (st , & _Py_ID (__class__ ), USE , LOCATION (e )))
2553
+ return 0 ;
2554
+ }
2552
2555
}
2553
2556
break ;
2554
2557
/* child nodes of List and Tuple will have expr_context set */
@@ -2733,6 +2736,9 @@ symtable_visit_params(struct symtable *st, asdl_arg_seq *args)
2733
2736
static int
2734
2737
symtable_visit_annotation (struct symtable * st , expr_ty annotation , void * key )
2735
2738
{
2739
+ // Annotations in local scopes are not executed and should not affect the symtable
2740
+ bool is_unevaluated = st -> st_cur -> ste_type == FunctionBlock ;
2741
+
2736
2742
if ((st -> st_cur -> ste_type == ClassBlock || st -> st_cur -> ste_type == ModuleBlock )
2737
2743
&& st -> st_cur -> ste_in_conditional_block
2738
2744
&& !st -> st_cur -> ste_has_conditional_annotations )
@@ -2764,11 +2770,17 @@ symtable_visit_annotation(struct symtable *st, expr_ty annotation, void *key)
2764
2770
return 0 ;
2765
2771
}
2766
2772
}
2767
- VISIT (st , expr , annotation );
2773
+ if (is_unevaluated ) {
2774
+ st -> st_cur -> ste_in_unevaluated_annotation = 1 ;
2775
+ }
2776
+ int rc = symtable_visit_expr (st , annotation );
2777
+ if (is_unevaluated ) {
2778
+ st -> st_cur -> ste_in_unevaluated_annotation = 0 ;
2779
+ }
2768
2780
if (!symtable_exit_block (st )) {
2769
2781
return 0 ;
2770
2782
}
2771
- return 1 ;
2783
+ return rc ;
2772
2784
}
2773
2785
2774
2786
static int
0 commit comments