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

Cody Piersall report at bugs.python.org
Sun Sep 17 22:20:36 EDT 2017


New submission from Cody Piersall:

If a some_module defines __all__, dir(some_module) should only return what is in __all__.  This is already a mechanism that Python provides to specify module-level APIs.  Currently, dir(some_module) returns some_module.__dict__.keys().

The concern with this enhancement is backwards compatibility.  It is conceivable that some library's code would be broken with the different return value of dir(some_module).  However, it seems unlikely that any code, other than tests, depends on the current behavior of dir(some_module).

If __all__ is not defined in some_module, the old behavior is preserved.

----------
messages: 302404
nosy: codypiersall
priority: normal
pull_requests: 3631
severity: normal
status: open
title: Enhance dir(module) to be informed by __all__ by updating module.__dir__
type: enhancement
versions: Python 3.7

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


More information about the New-bugs-announce mailing list