@@ -141,6 +141,7 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
141141 ste -> ste_needs_classdict = 0 ;
142142 ste -> ste_has_conditional_annotations = 0 ;
143143 ste -> ste_in_conditional_block = 0 ;
144+ ste -> ste_in_unevaluated_annotation = 0 ;
144145 ste -> ste_annotation_block = NULL ;
145146
146147 ste -> ste_has_docstring = 0 ;
@@ -2538,17 +2539,19 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
25382539 VISIT (st , expr , e -> v .Slice .step );
25392540 break ;
25402541 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 )) {
25512546 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+ }
25522555 }
25532556 break ;
25542557 /* 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)
27332736static int
27342737symtable_visit_annotation (struct symtable * st , expr_ty annotation , void * key )
27352738{
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+
27362742 if ((st -> st_cur -> ste_type == ClassBlock || st -> st_cur -> ste_type == ModuleBlock )
27372743 && st -> st_cur -> ste_in_conditional_block
27382744 && !st -> st_cur -> ste_has_conditional_annotations )
@@ -2764,11 +2770,17 @@ symtable_visit_annotation(struct symtable *st, expr_ty annotation, void *key)
27642770 return 0 ;
27652771 }
27662772 }
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+ }
27682780 if (!symtable_exit_block (st )) {
27692781 return 0 ;
27702782 }
2771- return 1 ;
2783+ return rc ;
27722784}
27732785
27742786static int
0 commit comments