Skip to content

Commit 0101037

Browse files
Document type annotation guidance
1 parent dce8cdf commit 0101037

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎developer-workflow/index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Development workflow
1111
lang-changes
1212
development-cycle
1313
stdlib
14+
type-annotations
1415
extension-modules
1516
c-api
1617
grammar
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.. _type-annotations:
2+
3+
=================
4+
Type annotations
5+
=================
6+
7+
CPython does not generally add type annotations to modules in the standard
8+
library's ``Lib`` directory. Static type checkers use the stubs maintained in
9+
`typeshed <https://github.com/python/typeshed>`__ for standard-library APIs.
10+
Keeping those stubs separate lets typing tools update their descriptions
11+
independently of Python's release cycle.
12+
13+
There are exceptions. Some standard-library modules and CPython development
14+
tools already contain annotations. When adding or changing annotated code,
15+
make sure the annotations are checked by the project's type-checking tools;
16+
unchecked annotations can become misleading or invalid. Do not add annotations
17+
to a standard-library module solely to provide type information to users.
18+
19+
This guidance describes the current practice, rather than a rule that every
20+
existing annotation must be removed. The practice and rationale are discussed
21+
in `Static type annotations in CPython
22+
<https://discuss.python.org/t/static-type-annotations-in-cpython/65068>`__.
23+
24+
CPython's user-facing documentation is maintained separately from the Python
25+
source code. When a type is useful to readers, include a clear, readable type
26+
description in the documentation following the usual :ref:`documentation
27+
guidelines <documenting>`; do not copy complex checker-oriented annotations
28+
without considering whether they help the reader.

0 commit comments

Comments
 (0)