[New-bugs-announce] [issue33277] Deprecate __loader__, __package__, __file__, and __cached__ on modules

Brett Cannon report at bugs.python.org
Fri Apr 13 17:48:22 EDT 2018


New submission from Brett Cannon <brett at python.org>:

If you look at https://docs.python.org/3/reference/import.html#import-related-module-attributes you will notice there are a lot of attributes on modules. But since the introduction of module specs (https://docs.python.org/3/library/importlib.html#importlib.machinery.ModuleSpec), all of those attributes became redundant.

Now some attributes can never be taken away based on common idioms in the Python community. __name__ can't go due to `if __name__ == '__main__'`. __path__ can't go due to people manipulating it with e.g. pkg_resources or pkgutil. The rest, though, don't have such strong idioms tied to them (and in the case of __package__, has actually been made officially redundant by the import system since Python 3.6). That means setting them is unnecessary and any time someone wants to read or potentially manipulate them they have to choose between those attributes or the spec (or update both). Either way it can lead to bugs (I know I have nearly forgotten to set both the spec and the attribute before).

I don't know if we can easily deprecate these attributes using __getattr__ on modules as added in Python 3.7, or if this is more of a documentation thing and need a long period of clearly messaging that these redundant attributes will no longer be set at some point.

----------
components: Library (Lib)
messages: 315269
nosy: brett.cannon, eric.snow
priority: normal
severity: normal
stage: test needed
status: open
title: Deprecate __loader__, __package__, __file__, and __cached__ on modules
versions: Python 3.8

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


More information about the New-bugs-announce mailing list