summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2018-10-14 17:01:03 (GMT)
committerGitHub <noreply@github.com>2018-10-14 17:01:03 (GMT)
commitde2aea0ff02fa9486365ce9d215bef150fae3a0b (patch)
tree83406b50dd7d3f85272bba218927d3ea0f005269 /Python
parentbd036d3d15fc1310ccc32a43a3296b8c157ac221 (diff)
downloadcpython-de2aea0ff02fa9486365ce9d215bef150fae3a0b.zip
cpython-de2aea0ff02fa9486365ce9d215bef150fae3a0b.tar.gz
cpython-de2aea0ff02fa9486365ce9d215bef150fae3a0b.tar.bz2
bpo-34939: Allow annotated global names in module namespace (GH-9844)
Allow annotated global names in the module namespace after the symbol is declared as global. Previously, only symbols annotated before they are declared as global (i.e. inside a function) were allowed. This change allows symbols to be declared as global before the annotation happens in the global scope.
Diffstat (limited to 'Python')
-rw-r--r--Python/symtable.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/Python/symtable.c b/Python/symtable.c
index d74f26f..dc934a5 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -1175,6 +1175,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
VISIT_QUIT(st, 0);
}
if ((cur & (DEF_GLOBAL | DEF_NONLOCAL))
+ && (st->st_cur->ste_symbols != st->st_global)
&& s->v.AnnAssign.simple) {
PyErr_Format(PyExc_SyntaxError,
cur & DEF_GLOBAL ? GLOBAL_ANNOT : NONLOCAL_ANNOT,