@@ -123,8 +123,10 @@ For namespace packages (see PEP 420), the ``py.typed`` file should be in the
123
123
submodules of the namespace, to avoid conflicts and for clarity.
124
124
125
125
This PEP does not support distributing typing information as part of
126
- module-only distributions. The code should be refactored into a package-based
127
- distribution and indicate that the package supports typing as described
126
+ module-only distributions or single-file modules within namespace packages.
127
+
128
+ The single-file module should be refactored into a package
129
+ and indicate that the package supports typing as described
128
130
above.
129
131
130
132
Stub-only Packages
@@ -156,6 +158,28 @@ in pip 9.0, if you update ``flyingcircus-stubs``, it will update
156
158
``--upgrade-strategy=only-if-needed `` flag. In pip 10.0 this is the default
157
159
behavior.
158
160
161
+ For namespace packages (see PEP 420), stub-only packages should
162
+ use the ``-stubs `` suffix on only the root namespace package.
163
+ All stub-only namespace packages should omit ``__init__.pyi `` files. ``py.typed ``
164
+ marker files are not necessary for stub-only packages, but similarly
165
+ to packages with inline types, if used, they should be in submodules of the namespace to
166
+ avoid conflicts and for clarity.
167
+
168
+ For example, if the ``pentagon `` and ``hexagon `` are separate distributions
169
+ installing within the namespace package ``shapes.polygons ``
170
+ The corresponding types-only distributions should produce packages
171
+ laid out as follows::
172
+
173
+ shapes-stubs
174
+ └── polygons
175
+ └── pentagon
176
+ └── __init__.pyi
177
+
178
+ shapes-stubs
179
+ └── polygons
180
+ └── hexagon
181
+ └── __init__.pyi
182
+
159
183
160
184
Type Checker Module Resolution Order
161
185
------------------------------------
@@ -180,6 +204,11 @@ resolve modules containing type information:
180
204
5. Typeshed (if used) - Provides the stdlib types and several third party
181
205
libraries.
182
206
207
+ If typecheckers identify a stub-only namespace package without the desired module
208
+ in step 3, they should continue to step 4/5. Typecheckers should identify namespace packages
209
+ by the absence of ``__init__.pyi ``. This allows different subpackages to
210
+ independently opt for inline vs stub-only.
211
+
183
212
Type checkers that check a different Python version than the version they run
184
213
on MUST find the type information in the ``site-packages ``/``dist-packages ``
185
214
of that Python version. This can be queried e.g.
@@ -204,8 +233,15 @@ typeshed folder and type checking the combined directory structure. Thus type
204
233
checkers MUST maintain the normal resolution order of checking ``*.pyi `` before
205
234
``*.py `` files.
206
235
207
- If a stub package is partial it MUST include ``partial\n `` in a top level
208
- ``py.typed `` file.
236
+ If a stub package distribution is partial it MUST include ``partial\n `` in a
237
+ ``py.typed `` file. For stub-packages distributing within a namespace
238
+ package (see PEP 420), the ``py.typed `` file should be in the
239
+ submodules of the namespace.
240
+
241
+ Type checkers should treat namespace packages within stub-packages as
242
+ incomplete since multiple distributions may populate them.
243
+ Regular packages within namespace packages in stub-package distributions
244
+ are considered complete unless a ``py.typed `` with ``partial\n `` is included.
209
245
210
246
211
247
Implementation
@@ -236,6 +272,11 @@ Vlasovskikh, Nathaniel Smith, and Guido van Rossum.
236
272
Version History
237
273
===============
238
274
275
+ * 2021-09-20
276
+
277
+ * Clarify expectations and typechecker behavior for stub-only namespace packages
278
+ * Clarify handling of single-file modules within namespace packages.
279
+
239
280
* 2018-07-09
240
281
241
282
* Add links to sample stub-only packages
0 commit comments