<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 14 September 2017 at 01:13, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="gmail-"><div><br></div></span><div>That last sentence is a key observation. Do we even know whether there are (non-toy) things that you can do *in principle* with __class__ assignment but which are too slow *in practice* to bother? And if yes, is __getattr__ fast enough? @property?</div><div><br></div></div></div></div></blockquote><div><br></div><div><div>I myself have never implemented deprecation warnings management nor lazy loading,</div><div>so it is hard to say if __class__ assignment is fast enough. For me it is more combination</div><div>of three factors:</div><div><br></div><div>* modest performance improvement</div><div>* some people might find __getattr__ clearer than __class__ assignment</div><div>* this would be consistent with how stubs work<br></div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div>IMO we're still looking for applications.<br></div></div><span class="gmail-"><br></span></div></div></blockquote><div><br></div><div>How about this</div><div><br></div><div>def allow_forward_references(*allowed):</div><div>    caller_globals = sys._getframe().__globals__<br></div><div>    def typing_getattr(name):</div><div>        if name in allowed:</div><div>            return name</div><div>        raise AttributeError(...)<br></div><div>    caller_globals.__getattr__ = typing_getattr</div><div><br></div><div>from typing_extensions import allow_forward_references<br></div><div>allow_forward_references('Vertex', 'Edge')<br></div><div></div><div><br></div><div>T = TypeVar('T', bound=Edge)</div><div><br></div><div>class Vertex(List[Edge]):</div><div>    def copy(self: T) -> T:</div><div>        ...</div><div><br></div><div>class Edge:</div><div>    ends: Tuple[Vertex, Vertex]</div><div>    ...</div><div><br></div><div>Look mum, no quotes! :-)</div><div><br></div><div>--</div><div>Ivan</div><div><br></div><div><br></div></div></div></div>