Skip to content

Commit 56ee760

Browse files
committed
Add draft name inclusion policy
1 parent 01f66cf commit 56ee760

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

docs/inclusion.rst

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Name Inclusion
2+
==============
3+
4+
Because of how fundamental name membership is, we hope to not meaningfully
5+
change this often. Simply put, Python is "batteries included" and these are the
6+
names of the batteries that you might expect your interpreter to come with.
7+
8+
Tenet 1: The intended use is platform- and version-agnostic import
9+
classification, whether that's for sorting or dependency analysis.
10+
11+
The primary goal is to be able to examine an import statement and decide whether
12+
that import is referencing code that the user doesn't need to install
13+
separately, for example from an import sorter to separate a "stdlib" block from
14+
a "third-party" block, or a tool like `checkdeps`_ to know that a name doesn't
15+
need to be attributed to a third-party project.
16+
17+
.. checkdeps: https://pypi.org/project/checkdeps/
18+
19+
For almost all real-world cases, this means we only need to examine the
20+
top-level name, which is simpler to store and query. Although namespace
21+
packages can affect what project a full name is attributed to, it doesn't
22+
generally change its third-partiness.
23+
24+
You also don't need to even query for relative imports, and what the relative
25+
import "evaluates to" doesn't matter.
26+
27+
A slightly more formal definition is:
28+
29+
Any top-level name that is supplied with an installed cpython interpreter
30+
compiled with standard flags on some platform (doesn't have to be your
31+
current one), unless its utility is completely outweighed by its danger.
32+
33+
Calling out a few important things there:
34+
35+
* It doesn't matter where you run ``stdlibs`` -- it takes a union view of all
36+
possible platforms and system dependencies being available.
37+
* Even if your particular install doesn't come with ``_bzip2.so`` because of a
38+
missing dependency, it's still one of the batteries.
39+
* We only handle cpython, and only vanilla for now, but that's out of
40+
disinterest rather than principle. If Microsoft offered a Python on its app
41+
store that came with an additional (definitively not third-party) module, we
42+
would probably include it.
43+
* We don't particularly care whether a name is a python module, compiled module,
44+
package, etc. If an import could theoretically succeed, that's enough. A
45+
little more explicitly, if someday there is a ``.pth`` file that makes an
46+
import work, we would probably include its name.
47+
* We differ from ``sys.stdlib_module_names`` in that we include "test" modules
48+
for historical and simplicity reasons. They're installed on most Python
49+
distributions, so meet the criteria for inclusion here. See
50+
`generate_stdlib_module_names.py`_ and some discussion on `issue 127484`_.
51+
* That said, we're willing to exclude names based on their lack of usefulness
52+
from the perspective of import classification -- when we started this project,
53+
python 2.7 was already obsolete and included a *dir* called ``test``. Almost
54+
all real-world code that does an ``import test`` would be a first-party
55+
import, and this is a choice name that people do use.
56+
57+
.. _generate_stdlib_module_names.py: https://github.com/python/cpython/blob/main/Tools/build/generate_stdlib_module_names.py
58+
.. _issue 127484: https://github.com/python/cpython/issues/127484

docs/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
:maxdepth: 1
66

77
api
8+
inclusion
89
changelog
910

0 commit comments

Comments
 (0)