[Python-ideas] except expression
ncoghlan at gmail.com
Tue Feb 18 00:54:57 CET 2014
On 18 Feb 2014 08:57, "Greg Ewing" <greg.ewing at canterbury.ac.nz> wrote:
> Chris Angelico wrote:
>> Maybe this is a good opportunity to introduce the concept of
>> "sub-scopes" for specific constructs. Comprehensions and 'as' clauses
>> (I doubt anyone will object to the statement try/except being brought
>> in line with this) could then use a sub-scope inside the existing
>> function; it'd affect only the LOAD_FAST opcode, I think - assignment
>> could delete it from the sub-scope and put it into the main scope.
> It *should* be possible to handle this entirely at
> compile time. Conceptually, all you need to do is
> rename the names in the subscope so that they
> don't clash with anything in the outer scope, and
> then generate bytecode as usual.
> I haven't studied the compiler closely enough to
> tell how difficult this would be to achieve, though.
> Whoever implemented inner scopes for list comprehensions
> reportedly found it harder than he liked at the time.
That was me, and it's handling nested closures correctly that gets
excruciatingly difficult. In theory, the compiler has enough info to figure
out the details and generate appropriate inline code, but in practice,
reusing the existing closure support made the change so much simpler to
implement that was the option I eventually chose.
While that simplicity of implementation did come at the cost of making the
behaviour at class scope a bit quirky, those quirks already existed for
generator expressions, so they even had the virtue of consistency in their
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas