Skip to content

Commit 9642a5a

Browse files
authored
Tweak the typing spec's module resolution to more closely emulate Python's runtime semantics (python#1772)
1 parent 21d67ca commit 9642a5a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

docs/spec/distributing.rst

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,9 @@ Partial Stub Packages
199199
Many stub packages will only have part of the type interface for libraries
200200
completed, especially initially. For the benefit of type checking and code
201201
editors, packages can be "partial". This means modules not found in the stub
202-
package SHOULD be searched for in part four of the module resolution
203-
order below, namely :term:`inline` packages.
202+
package SHOULD be searched for in parts five and six of the module resolution
203+
order below, namely :term:`inline` packages and any third-party stubs the type
204+
checker chooses to vendor.
204205

205206
Type checkers should merge the stub package and runtime package
206207
directories. This can be thought of as the functional equivalent of copying the
@@ -235,19 +236,27 @@ resolve modules containing type information:
235236

236237
2. User code - the files the type checker is running on.
237238

238-
3. :term:`Stub <stub>` packages - these packages SHOULD supersede any installed inline
239+
3. Typeshed stubs for the standard library. These will usually be vendored by
240+
type checkers, but type checkers SHOULD provide an option for users to
241+
provide a path to a directory containing a custom or modified version of
242+
typeshed; if this option is provided, type checkers SHOULD use this as the
243+
canonical source for standard-library types in this step.
244+
245+
4. :term:`Stub <stub>` packages - these packages SHOULD supersede any installed inline
239246
package. They can be found in directories named ``foopkg-stubs`` for
240247
package ``foopkg``.
241248

242-
4. Packages with a ``py.typed`` marker file - if there is nothing overriding
249+
5. Packages with a ``py.typed`` marker file - if there is nothing overriding
243250
the installed package, *and* it opts into type checking, the types
244251
bundled with the package SHOULD be used (be they in ``.pyi`` type
245252
stub files or inline in ``.py`` files).
246253

247-
5. Typeshed - only for modules in the standard library.
254+
6. If the type checker chooses to additionally vendor any third-party stubs
255+
(from typeshed or elsewhere), these SHOULD come last in the module
256+
resolution order.
248257

249258
If typecheckers identify a stub-only namespace package without the desired module
250-
in step 3, they should continue to step 4/5. Typecheckers should identify namespace packages
259+
in step 4, they should continue to step 5/6. Typecheckers should identify namespace packages
251260
by the absence of ``__init__.pyi``. This allows different subpackages to
252261
independently opt for inline vs stub-only.
253262

0 commit comments

Comments
 (0)