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 <>
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).
Date User Action Args
2017-09-18 03:42:20ncoghlansetrecipients: + ncoghlan, brett.cannon, rhettinger, terry.reedy, codypiersall
2017-09-18 03:42:20ncoghlansetmessageid: <>
2017-09-18 03:42:20ncoghlanlinkissue31503 messages
2017-09-18 03:42:19ncoghlancreate