diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-10-14 11:40:15 (GMT) |
---|---|---|
committer | Ćukasz Langa <lukasz@langa.pl> | 2019-10-14 11:40:15 (GMT) |
commit | 927f07c816aad9f8ed961d7ace6a367837f7fa8f (patch) | |
tree | 6fdf864d74436422335c89ebdff2f3afbc66866f /Python/symtable.c | |
parent | ac53ba6c7c0c43100bab8bc427d54563d9b65a0e (diff) | |
download | cpython-927f07c816aad9f8ed961d7ace6a367837f7fa8f.zip cpython-927f07c816aad9f8ed961d7ace6a367837f7fa8f.tar.gz cpython-927f07c816aad9f8ed961d7ace6a367837f7fa8f.tar.bz2 |
bpo-38469: Handle named expression scope with global/nonlocal keywords (GH-16755) (#16760)
The symbol table handing of PEP572's assignment expressions is not resolving correctly the scope of some variables in presence of global/nonlocal keywords in conjunction with comprehensions.
(cherry picked from commit fd5c414880b2e05720b9cf14ab0b0d7ae2b7d925)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Python/symtable.c')
-rw-r--r-- | Python/symtable.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/Python/symtable.c b/Python/symtable.c index f2453db..b871358 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -1467,10 +1467,16 @@ symtable_extend_namedexpr_scope(struct symtable *st, expr_ty e) continue; } - /* If we find a FunctionBlock entry, add as NONLOCAL/LOCAL */ + /* If we find a FunctionBlock entry, add as GLOBAL/LOCAL or NONLOCAL/LOCAL */ if (ste->ste_type == FunctionBlock) { - if (!symtable_add_def(st, target_name, DEF_NONLOCAL)) - VISIT_QUIT(st, 0); + long target_in_scope = _PyST_GetSymbol(ste, target_name); + if (target_in_scope & DEF_GLOBAL) { + if (!symtable_add_def(st, target_name, DEF_GLOBAL)) + VISIT_QUIT(st, 0); + } else { + if (!symtable_add_def(st, target_name, DEF_NONLOCAL)) + VISIT_QUIT(st, 0); + } if (!symtable_record_directive(st, target_name, e->lineno, e->col_offset)) VISIT_QUIT(st, 0); |