
On 16/01/21 9:38 am, Guido van Rossum wrote:
On Fri, Jan 15, 2021 at 10:53 AM Larry Hastings <larry@hastings.org <mailto:larry@hastings.org>> wrote:
class OuterCls: class InnerCls: def method(a:OuterCls.InnerCls=None): pass
We've turned the local reference into a global reference, and we already know globals work fine.
I think this is going too far. A static method defined in InnerCls does not see InnerCls (even after the class definitions are complete). E.g. ``` class Outer: class Inner: @staticmethod def foo(): return Inner ``` If you then call Outer.Inner.foo() you get "NameError: name 'Inner' is not defined".
I'm not so sure about that. Conceptually, annotations are evaluated in the environment existing when the class scope is being constructed. The fact that we're moving them into a closure is an implementation detail that I don't think should be exposed.
What if we want to refer to something defined /after/ the annotation?
def outerfn(): class OuterCls: class InnerCls: def method(a:zebra=None): pass ...
We haven't seen the definition of "zebra" yet, so we don't know what approach to take.
I don't think that should be a problem. The compiler already knows about all the assignments occurring in a scope before starting to generate code for it. -- Greg