[issue21761] [doc] language reference describes the role of module.__file__ inaccurately

Eric Snow report at bugs.python.org
Mon Dec 6 19:49:59 EST 2021


Eric Snow <ericsnowcurrently at gmail.com> added the comment:

The key point is that loaders should be using the spec, not any of the module attrs (like `__file__` and `__cached__`), nor setting them.

For the specific paragraph I referenced, it would look more like:

  It is also appropriate to set __cached__ when __file__ is not set.
  However, that scenario is quite atypical.  Ultimately, __file__ and
  __cached__ are set by the import system from the module spec provided
  by the finder.  The spec instructs the loader.  If a loader can load
  from a cached module but otherwise does not load from a file, that
  atypical scenario may be appropriate.

----------

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


More information about the Python-bugs-list mailing list