Skip to content

Commit f9b5840

Browse files
native-apimiss-islington
authored andcommitted
bpo-33944: note about the intended use of code in .pth files (GH-10131)
https://bugs.python.org/issue33944
1 parent 6f55b03 commit f9b5840

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Doc/library/site.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ directory rather than a file. No item is added to ``sys.path`` more than
6161
once. Blank lines and lines beginning with ``#`` are skipped. Lines starting
6262
with ``import`` (followed by space or tab) are executed.
6363

64+
.. note::
65+
66+
An executable line in a :file:`.pth` file is run at every Python startup,
67+
regardless of whether a particular module is actually going to be used.
68+
Its impact should thus be kept to a minimum.
69+
The primary intended purpose of executable lines is to make the
70+
corresponding module(s) importable
71+
(load 3rd-party import hooks, adjust :envvar:`PATH` etc).
72+
Any other initialization is supposed to be done upon a module's
73+
actual import, if and when it happens.
74+
Limiting a code chunk to a single line is a deliberate measure
75+
to discourage putting anything more complex here.
76+
6477
.. index::
6578
single: package
6679
triple: path; configuration; file
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added a note about the intended use of code in .pth files.

0 commit comments

Comments
 (0)