Mercurial > cpython-lru_cache-weakref
diff Python/compile.c @ 17702:e3f0fd38c24b legacy-trunk
Several small changes. Mostly reformatting, adding parens.
Check for free in class and method only if nested scopes are enabled.
Add assertion to verify that no free variables occur when nested
scopes are disabled.
XXX When should nested scopes by made non-optional on the trunk?
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Tue, 08 May 2001 04:12:34 +0000 |
| parents | 8ff76cf30a8c |
| children | 437482fe55e6 |
line wrap: on
line diff
--- a/Python/compile.c Tue May 08 04:08:59 2001 +0000 +++ b/Python/compile.c Tue May 08 04:12:34 2001 +0000 @@ -4078,7 +4078,7 @@ anything here. */ if (is_free(flags ^ DEF_FREE_CLASS) - || flags == DEF_FREE_CLASS) + || (flags == DEF_FREE_CLASS)) return 0; v = PyInt_FromLong(si->si_nfrees++); dict = c->c_freevars; @@ -4260,6 +4260,7 @@ if (!(flags & DEF_BOUND)) return 0; + /* The semantics of this code will change with nested scopes. It is defined in the current scope and referenced in a child scope. Under the old rules, the child will see a @@ -4364,8 +4365,10 @@ 2. Free variables in methods that are also class variables or declared global. */ - if (flags & (DEF_FREE | DEF_FREE_CLASS)) { + if (st->st_nested_scopes) { + if (flags & (DEF_FREE | DEF_FREE_CLASS)) { symtable_resolve_free(c, name, flags, &si); + } } if (flags & DEF_STAR) { @@ -4425,15 +4428,11 @@ } } - /* - fprintf(stderr, - "cells %d: %s\n" - "frees %d: %s\n", - si.si_ncells, PyObject_REPR(c->c_cellvars), - si.si_nfrees, PyObject_REPR(c->c_freevars)); - */ assert(PyDict_Size(c->c_freevars) == si.si_nfrees); + if (st->st_nested_scopes == 0) + assert(si.si_nfrees == 0); + if (si.si_ncells > 1) { /* one cell is always in order */ if (symtable_cellvar_offsets(&c->c_cellvars, c->c_argcount, c->c_varnames, c->c_flags) < 0) @@ -4538,7 +4537,9 @@ referenced in scope B contained (perhaps indirectly) in A and there are no scopes with bindings for N between B and A, then N - is global in B. + is global in B. Unless A is a class scope, + because class scopes are not considered for + nested scopes. */ if (v && (ste->ste_type != TYPE_CLASS)) { int flags = PyInt_AS_LONG(v);
