
Oct. 21, 2020
1:01 a.m.
Steven D'Aprano wrote:
We could rescue the concept by saying that any reference to locals() inside the function disables the elimination, but of course locals can be shadowed or aliased, and we can't expect the interpreter to do a full analysis of the entire program.
We already do something similar for zero-argument super():
duper = super class C: ... def __init__(self): ... duper() ... C() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 3, in __init__ RuntimeError: super(): __class__ cell not found
Besides, locals() is already a bit weird at best:
[locals() for _ in [None]] [{'.0': <tuple_iterator object at 0x7ffa6c609280>, '_': None}]