[issue31503] Enhance dir(module) to be informed by __all__ by updating module.__dir__

Nick Coghlan report at bugs.python.org
Mon Sep 18 01:02:29 EDT 2017


Nick Coghlan added the comment:

As far the implementation goes, since the `__dir__` overload support in the `dir()` builtin ignores instance dictionaries, this could be implemented in module.__dir__ (or object.__dir__) rather than directly in the builtin.

Alternatively, it could use a different attribute name rather than having `__dir__` be a list of strings on instances, and a protocol method on classes.

If we went with a different name, then I think `__public__` would be a reasonable option, since the purpose of the attribute is to make it easy to programmatically distinguish public attributes from non-public ones (independently of the established leading underscore convention, which doesn't work well for transitive module references).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31503>
_______________________________________


More information about the Python-bugs-list mailing list