Skip to content

Commit 2aea75f

Browse files
RaghuRaghu
authored andcommitted
Clarify module.__file__ documentation
1 parent 9df2b6c commit 2aea75f

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Doc/reference/datamodel.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,9 +1073,8 @@ this approach.
10731073

10741074
.. attribute:: module.__file__
10751075

1076-
:attr:`!__file__` is an optional attribute that
1077-
may or may not be set. Both attributes should be a :class:`str` when they
1078-
are available.
1076+
:attr:`!__file__` is an optional attribute that may or may not be set.
1077+
When it is set, it should be a :class:`str`.
10791078

10801079
An optional attribute, :attr:`!__file__` indicates the pathname of the file
10811080
from which the module was loaded (if loaded from a file), or the pathname of
@@ -1084,6 +1083,9 @@ this approach.
10841083
modules that are statically linked into the interpreter, and the
10851084
:ref:`import system <importsystem>` may opt to leave it unset if it
10861085
has no semantic meaning (for example, a module loaded from a database).
1086+
For modules loaded from a file by the import system, it is usually an
1087+
absolute path. However, other loaders may set it to a different value, so
1088+
code that needs an absolute path should normalize it explicitly.
10871089

10881090
.. deprecated-removed:: 3.13 3.15
10891091
Setting ``__cached__`` on a module while failing to set

0 commit comments

Comments
 (0)