This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients brett.cannon, codypiersall, ncoghlan, rhettinger, terry.reedy
Date 2017-09-18.03:42:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1505706140.38.0.766740187553.issue31503@psf.upfronthosting.co.za>
In-reply-to
Content
While I agree changing the default would be risky from a compatibility perspective, I do think it would be helpful to offer a straightforward way to filter out transitive imports and other non-public implementation details from the result of `dir(module)`, and require folks to use `list(vars(module).keys())` if they want a reliably complete listing of all global variables defined in a module.

The simplest spelling that comes to mind would be to allow people to write:

    __dir__ = __all__

to get ``__all__`` to also affect the result of ``dir()``, permitting module authors to make their own determination as to whether they consider "The result of dir() includes non-public implementation details" to be covered by any backwards compatibility guarantees they might offer.

A less simple, but potentially more flexible, mechanism would be to require that to be spelled as:

    def __dir__():
        return __all__

but I'm not sure the extra flexibility would be useful in any meaningful way (especially if one of the options for easier definition of dynamic module level properties were eventually adopted).
History
Date User Action Args
2017-09-18 03:42:20ncoghlansetrecipients: + ncoghlan, brett.cannon, rhettinger, terry.reedy, codypiersall
2017-09-18 03:42:20ncoghlansetmessageid: <1505706140.38.0.766740187553.issue31503@psf.upfronthosting.co.za>
2017-09-18 03:42:20ncoghlanlinkissue31503 messages
2017-09-18 03:42:19ncoghlancreate