[Python-ideas] PEP 562

Cody Piersall cody.piersall at gmail.com
Sun Sep 10 18:01:15 EDT 2017


Sorry for top posting!  I'm on a phone. I still think the better way to
solve the custom dir()  would be to change the module __dir__ method to
check if __all__ is defined and use it to generate the result if it exists.
This seems like a logical enhancement to me, and I'm planning on writing a
patch to implement this. Whether it would be accepted is still an open
issue though.

Cody

On Sep 10, 2017 3:19 PM, "Nathaniel Smith" <njs at pobox.com> wrote:

The main two use cases I know of for this and PEP 549 are lazy imports of
submodules, and deprecating attributes. If we assume that you only want
lazy imports to show up in dir() and don't want deprecated attributes to
show up in dir() (and I'm not sure this is what you want 100% of the time,
but it seems like the most reasonable default to me), then currently you
need one of the PEPs for one of the cases and the other PEP for the other
case.

Would it make more sense to add direct support for lazy imports and
attribute deprecation to ModuleType? This might look something like
metamodule's FancyModule type:

    https://github.com/njsmith/metamodule/blob/ee54d49100a9a06
ffff341bb10a4d3549642139f/metamodule.py#L20

-n
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170910/6292212e/attachment-0001.html>


More information about the Python-ideas mailing list