Skip to content

Commit

Permalink
[spec] Update typeshed language to conform to reality (python#1571)
Browse files Browse the repository at this point in the history
* Describe typeshed as a "project", not a "repository".
* While typeshed still contains third-party stubs, those are usually not distributed with type checkers, but available from PyPI. Update the language accordingly.
* This also means that step 5 of the import resolution ordering should reference the stdlib only.

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
  • Loading branch information
srittau and hauntsaninja committed Jan 16, 2024
1 parent ab2372a commit e26c686
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions docs/spec/distributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ Additional notes on stub files:
Any identifier not defined in the stub is therefore assumed to be of type
``Any``.

The Typeshed Repo
^^^^^^^^^^^^^^^^^

There is a `shared repository <https://github.com/python/typeshed>`_ where useful stubs are being
collected. Policies regarding the stubs collected here are
decided separately and reported in the repo's documentation.
The Typeshed Project
^^^^^^^^^^^^^^^^^^^^

The `typeshed project <https://github.com/python/typeshed>`_ contains type
stubs for the standard library (vendored or handled specially by type checkers)
and type stubs for third-party libraries that don't ship their own type information
(typically distributed via PyPI). Policies regarding the
stubs collected there are decided separately and described in the project's
documentation.

Type information in libraries
-----------------------------
Expand Down Expand Up @@ -194,13 +196,13 @@ Partial Stub Packages
Many stub packages will only have part of the type interface for libraries
completed, especially initially. For the benefit of type checking and code
editors, packages can be "partial". This means modules not found in the stub
package SHOULD be searched for in parts four and five of the module resolution
order above, namely inline packages and typeshed.
package SHOULD be searched for in part four of the module resolution
order below, namely inline packages.

Type checkers should merge the stub package and runtime package or typeshed
Type checkers should merge the stub package and runtime package
directories. This can be thought of as the functional equivalent of copying the
stub package into the same directory as the corresponding runtime package or
typeshed folder and type checking the combined directory structure. Thus type
stub package into the same directory as the corresponding runtime package
and type checking the combined directory structure. Thus type
checkers MUST maintain the normal resolution order of checking ``*.pyi`` before
``*.py`` files.

Expand All @@ -216,8 +218,8 @@ are considered complete unless a ``py.typed`` with ``partial\n`` is included.

.. _mro:

Import resolutiong ordering
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Import resolution ordering
^^^^^^^^^^^^^^^^^^^^^^^^^^

The following is the order in which type checkers supporting this specification SHOULD
resolve modules containing type information:
Expand All @@ -238,8 +240,7 @@ resolve modules containing type information:
bundled with the package SHOULD be used (be they in ``.pyi`` type
stub files or inline in ``.py`` files).

5. Typeshed (if used) - Provides the stdlib types and several third party
libraries.
5. Typeshed - only for modules in the standard library.

If typecheckers identify a stub-only namespace package without the desired module
in step 3, they should continue to step 4/5. Typecheckers should identify namespace packages
Expand Down

0 comments on commit e26c686

Please sign in to comment.