<div dir="ltr">Picking up this thread as part of the PEP 562 and PEP 549 review. I like PEP 562 most, but I propose to add special-casing for `__dir__`. Not quite as proposed above (making the C level module_dir() look for `__all__`) but a bit more general -- making module_dir() look for `__dir__` and call that if present and callable. Ivan what do you think of that idea? It should be simple to add to your existing implementation. (<a href="https://github.com/ilevkivskyi/cpython/pull/3#issuecomment-343591293">https://github.com/ilevkivskyi/cpython/pull/3#issuecomment-343591293</a>)<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 12, 2017 at 1:26 AM, Ivan Levkivskyi <span dir="ltr"><<a href="mailto:levkivskyi@gmail.com" target="_blank">levkivskyi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>@Anthony</div><span class=""><div>> module.__getattr__ works pretty well for normal access, after being</div><div>> imported by another module, but it doesn't properly trigger loading by</div><div>> functions defined in the module's own namespace.</div><div><br></div></span><div>The idea of my PEP is to be very simple (both semantically and in terms</div><div>of implementation). This is why I don't want to add any complex logic.</div><div>People who will want to use __getattr__ for lazy loading still can do this</div><div>by importing submodules.<br></div><div><br></div><div>@Nathaniel @INADA</div><span class=""><div>> The main two use cases I know of for this and PEP 549 are lazy imports</div><div>> of submodules, and deprecating attributes.</div><div><br></div></span><div>Yes, lazy loading seems to be a popular idea :-)</div><div>I will add the simple recipe by Inada to the PEP since it will already work.<br></div><div><br></div><div>@Cody<br></div><span class=""><div>> I still think the better way<br>> to
solve the custom dir() would be to change the module __dir__<br>> method to
check if __all__ is defined and use it to generate the<br>> result if it
exists. This seems like a logical enhancement to me,<br>> and I'm planning on
writing a patch to implement this. Whether it<br>> would be accepted is
still an open issue though.<br><br></div></span>This seems a reasonable rule to me, I can also make this patch if</div><div>you will not have time.</div><div><br></div><div>@Guido</div><div>What do you think about the above idea?</div><div><br></div><div>--<br></div>Ivan<br><br><br></div>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>