Mercurial > cpython-lru_cache-weakref
diff Python/compile.c @ 16871:d675d75af839 legacy-trunk
Warn about global statement at the module level.
Do better accounting for global variables.
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Wed, 28 Feb 2001 23:44:45 +0000 |
| parents | 77a5470299db |
| children | 9d018a3d7946 |
line wrap: on
line diff
--- a/Python/compile.c Wed Feb 28 23:34:21 2001 +0000 +++ b/Python/compile.c Wed Feb 28 23:44:45 2001 +0000 @@ -4178,7 +4178,7 @@ { char buf[500]; PyObject *children, *v; - PySymtableEntryObject *child; + PySymtableEntryObject *child = NULL; int i; if (!(flags & DEF_BOUND)) @@ -4202,7 +4202,9 @@ if (!(cflags & DEF_BOUND)) break; } - + + assert(child != NULL); + sprintf(buf, "local name '%.100s' in '%.100s' shadows " "use of '%.100s' as global in nested scope '%.100s'", PyString_AS_STRING(name), @@ -4328,6 +4330,10 @@ if (PyDict_SetItem(c->c_globals, name, implicit) < 0) goto fail; + v = PyInt_FromLong(flags); + if (PyDict_SetItem(st->st_global, name, v)) + goto fail; + Py_DECREF(v); } } } @@ -4360,6 +4366,7 @@ st->st_nscopes = 0; st->st_errors = 0; st->st_tmpname = 0; + st->st_global_star = 0; st->st_private = NULL; return st; fail: @@ -4922,6 +4929,12 @@ { int i; + if (st->st_nscopes == 1) { + if (symtable_warn(st, + "global statement has no meaning at module level") < 0) + return; + } + for (i = 1; i < NCH(n); i += 2) { char *name = STR(CHILD(n, i)); int flags; @@ -4991,6 +5004,8 @@ } if (TYPE(CHILD(n, 3)) == STAR) { st->st_cur->ste_optimized |= OPT_IMPORT_STAR; + if (st->st_nscopes == 1) + st->st_global_star = 1; } else { for (i = 3; i < NCH(n); i += 2) { node *c = CHILD(n, i);
