File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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.
You can’t perform that action at this time.
0 commit comments