<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Thu, 14 Sep 2017 at 12:09 Ivan Levkivskyi <<a href="mailto:levkivskyi@gmail.com">levkivskyi@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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="m_-452370592657302069gmail-"><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></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><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.</div></div></div></div></div></blockquote><div><br></div><div>For lazy loading it is, but that's because after the lazy load, module.__class__ is set back to its original value, so any performance penalty is paid only once upon triggering __getattribute__ on the lazy module.</div><div><br></div><div>IOW no one has complained and I know plenty of places using the lazy loading mechanism in importlib at scale. :)<br></div><div><br></div><div>-Brett<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div> 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></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><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="m_-452370592657302069gmail-"><br></span></div></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><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>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/brett%40python.org" rel="noreferrer" target="_blank">https://mail.python.org/mailman/options/python-dev/brett%40python.org</a><br>
</blockquote></div></div>