[Python-Dev] Informal educator feedback on PEP 572 (was Re: 2018 Python Language Summit coverage, last part)

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Jun 27 19:55:20 EDT 2018


Nick Coghlan wrote:
> I'm OK with a target scope declaration construct having
> lexical-scope-dependent behaviour - exactly what "nonlocal NAME" will
> do depends on both the nature of the current scope,

Yes, but my point is that having an explicit "parentlocal" scope
declaration doesn't help to make anything more orthogonal,
because there's no way it can have *exactly* the same effect
as a comprehension's implicit parent-local scoping.

In other words, taking a comprehension and manually expanding
it into a function with parentlocal declarations wouldn't
give you something exactly equivalent to the original.
If that's the purpose of having an explicit parentlocal,
then it fails at that purpose.

If that's *not* the purpose, then I'm not really sure what
the purpose is, because I can't think of a situation where
I'd choose to use parentlocal instead of nonlocal with an
explicit assignment in the outer scope. Except maybe for the
class-scope situation, which seems like an extremely obscure
reason to introduce a whole new scoping concept with its
own keyword.

-- 
Greg


More information about the Python-Dev mailing list