@@ -626,7 +626,16 @@ async def call(self, ast_ctx, *args, **kwargs):
626
626
sym_table [name ] = value
627
627
else :
628
628
sym_table [name ] = EvalLocalVar (name )
629
- ast_ctx .sym_table_stack .append (ast_ctx .sym_table )
629
+ if ast_ctx .global_ctx != self .global_ctx :
630
+ #
631
+ # switch to the global symbol table in the global context
632
+ # where the function was defined
633
+ #
634
+ prev_sym_table = [ast_ctx .global_sym_table , ast_ctx .sym_table , ast_ctx .sym_table_stack ]
635
+ ast_ctx .global_sym_table = self .global_ctx .get_global_sym_table ()
636
+ ast_ctx .sym_table_stack = [ast_ctx .global_sym_table ]
637
+ else :
638
+ ast_ctx .sym_table_stack .append (ast_ctx .sym_table )
630
639
ast_ctx .sym_table = sym_table
631
640
code_str , code_list = ast_ctx .code_str , ast_ctx .code_list
632
641
ast_ctx .code_str , ast_ctx .code_list = self .code_str , self .code_list
@@ -644,9 +653,12 @@ async def call(self, ast_ctx, *args, **kwargs):
644
653
val = None
645
654
if ast_ctx .get_exception_obj ():
646
655
break
647
- ast_ctx .sym_table = ast_ctx .sym_table_stack .pop ()
648
656
ast_ctx .curr_func = prev_func
649
657
ast_ctx .code_str , ast_ctx .code_list = code_str , code_list
658
+ if ast_ctx .global_ctx != self .global_ctx :
659
+ ast_ctx .global_sym_table , ast_ctx .sym_table , ast_ctx .sym_table_stack = prev_sym_table
660
+ else :
661
+ ast_ctx .sym_table = ast_ctx .sym_table_stack .pop ()
650
662
return val
651
663
652
664
0 commit comments