This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: [doc] language reference describes the role of module.__file__ inaccurately
Type: Stage: patch review
Components: Documentation Versions: Python 3.11, Python 3.10, Python 3.9
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: AlexWaygood, barry, brett.cannon, docs@python, eric.snow, iritkatriel, ncoghlan, slateny, vidhya
Priority: normal Keywords: easy, patch

Created on 2014-06-14 20:33 by eric.snow, last changed 2022-04-11 14:58 by admin.

Pull Requests
URL Status Linked Edit
PR 31565 open slateny, 2022-02-25 06:39
Messages (7)
msg220578 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2014-06-14 20:33
The language reference [1] says:

  Ultimately, the loader is what makes use of __file__ and/or __cached__

This implies that loaders should use __file__ and __cached__ when loading a module.  Instead loaders are meant to implement exec_module() and use the spec that's passed in.

The entire section should have a clear note that loaders are not meant to rely a module's import-related attributes.

msg407721 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-12-05 17:43
Would it suffice to change

"Ultimately, the loader is what makes use of __file__ and/or __cached__"


"Ultimately, the loader set the values of __file__ and/or __cached__"

msg407866 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2021-12-06 21:37
> "Ultimately, the loader set the values of __file__ and/or __cached__"

Change it to "sets" and +1 from me!
msg407885 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2021-12-07 00:49
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.
msg414159 - (view) Author: Vidhya (vidhya) * Date: 2022-02-27 15:51
If this is still open, I would like to work on this. Please let me know.
msg414160 - (view) Author: Alex Waygood (AlexWaygood) * (Python triager) Date: 2022-02-27 16:29
Hi Vidhya — @slateny submitted a PR for this issue only two days ago (you can see that it's linked to this BPO issue in the "Pull Requests" field). I think it would be good to wait until that has been reviewed before doing any work on a possible PR for this issue :)

If you'd like to help out with this issue, you'd of course be very welcome to submit a review for @slateny's patch.
msg414207 - (view) Author: Vidhya (vidhya) * Date: 2022-02-28 16:26
Thanks Alex. I will look into @slateny's patch.
Date User Action Args
2022-04-11 14:58:04adminsetgithub: 65960
2022-02-28 16:26:50vidhyasetmessages: + msg414207
2022-02-27 16:29:07AlexWaygoodsetnosy: + AlexWaygood
messages: + msg414160
2022-02-27 15:51:01vidhyasetnosy: + vidhya
messages: + msg414159
2022-02-25 06:39:03slatenysetkeywords: + patch
nosy: + slateny

pull_requests: + pull_request29687
stage: needs patch -> patch review
2021-12-07 00:49:59eric.snowsetmessages: + msg407885
2021-12-06 22:01:31iritkatrielsetkeywords: + easy
2021-12-06 21:37:42brett.cannonsetmessages: + msg407866
2021-12-05 17:43:07iritkatrielsetnosy: + iritkatriel
title: language reference describes the role of module.__file__ inaccurately -> [doc] language reference describes the role of module.__file__ inaccurately
messages: + msg407721

versions: + Python 3.9, Python 3.10, Python 3.11, - Python 3.4, Python 3.5
2014-06-14 20:35:11eric.snowsetassignee: docs@python

nosy: + docs@python
components: + Documentation
stage: needs patch
2014-06-14 20:33:24eric.snowcreate