mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
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.
This commit is contained in:
parent
bd036d3d15
commit
de2aea0ff0
3 changed files with 17 additions and 0 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue