Most notably, in the synthetic functions created for generator expressions and comprehensions, a parentlocal declaration in a child scope would imply a parentlocal declaration in the synthetic function as well, propagating back up the chain of nested lexical scopes until it terminated in one of the above three permitted targets.
Using the explicit forms would then look like:
from __future import parent_scopes # Enable the explicit declaration forms
class C:
classlocal _n # Declares _n as a cell akin to __class__ rather than a class attribute
_n = []
@staticmethod
def get_count():
return len(_n)
assert not hasattr(C, "_n")
assert C.get_count() == 0
def _writes_to_parent_scope():
parentlocal outer_name
outer_name = 42
assert outer_name == 42
I'm still doubtful the complexity of actually doing
that is warranted, but I'm now satisfied the semantics can be well
specified in a way that allows us to retain the explanation of generator
expressions and comprehensions in terms of their statement level
counterparts (with the added bonus of making "__class__" a little less of a magically unique snowflake along the way).
Cheers,
Nick.