8000 bpo-21761: Clarify __file__/__cached__ in import reference (GH-31565) · python/cpython@b87f7f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit b87f7f2

Browse files
authored
bpo-21761: Clarify __file__/__cached__ in import reference (GH-31565)
Automerge-Triggered-By: GH:brettcannon
1 parent f703c96 commit b87f7f2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Doc/reference/import.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,15 +610,16 @@ the module.
610610
import system may opt to leave it unset if it has no semantic
611611
meaning (e.g. a module loaded from a database).
612612

613-
If ``__file__`` is set, it may also be appropriate to set the
614-
``__cached__`` attribute which is the path to any compiled version of
613+
If ``__file__`` is set then the ``__cached__`` attribute might also
614+
be set, which is the path to any compiled version of
615615
the code (e.g. byte-compiled file). The file does not need to exist
616616
to set this attribute; the path can simply point to where the
617617
compiled file would exist (see :pep:`3147`).
618618

619-
It is also appropriate to set ``__cached__`` when ``__file__`` is not
619+
Note that ``__cached__`` may be set even if ``__file__`` is not
620620
set. However, that scenario is quite atypical. Ultimately, the
621-
loader is what makes use of ``__file__`` and/or ``__cached__``. So
621+
loader is what makes use of the module spec provided by the finder
622+
(from which ``__file__`` and ``__cached__`` are derived). So
622623
if a loader can load from a cached module but otherwise does not load
623624
from a file, that atypical scenario may be appropriate.
624625

0 commit comments

Comments
 (0)
0