Nick Coghlan added the comment:
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).
----------
nosy: +ncoghlan
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue31503>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com