[Python-ideas] Statement local functions and classes (aka PEP 3150 is dead, say 'Hi!' to PEP 403)
Greg Ewing
greg.ewing at canterbury.ac.nz
Fri Oct 14 09:47:57 CEST 2011
Nick Coghlan wrote:
> So, keep the PEP 3150 syntax, but don't make the inner suite special
> aside from the out of order execution?
That's right. If we're willing to accept the idea of the
def in a postdef statement binding a name in the surrounding
scope, then we've already decided that we don't care about
polluting the main scope -- and it would make PEP 3150 a
heck of a lot easier to both specify and implement.
Having said that, I think there might be a way of
implementing PEP 3150 with scoping and all that isn't too
bad.
The main difficulties seem to concern class scopes.
Currently they're kept in a dict while they're being
built, like function local scopes used to be before
they were optimised.
We could change that so that they're compiled in the
same way as a normal function scope, and then use the
equivalent of locals() at the end to build the class
dict. The body of a 'given' statement could then be
compiled as a separate function with access to the
class scope. Nested 'def' and 'class' statements, on
the other hand, would be compiled with the surrounding
scope deliberately excluded.
--
Greg
More information about the Python-ideas
mailing list