Skip to content

Commit 02be4b5

Browse files
Add section on supported type-system features (#5479)
1 parent 61320cb commit 02be4b5

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

CONTRIBUTING.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,48 @@ See [PEP 484](http://www.python.org/dev/peps/pep-0484/) for the exact
126126
syntax of the stub files and [below](#stub-file-coding-style) for the
127127
coding style used in typeshed.
128128

129+
### Supported type system features
130+
131+
Since PEP 484 was accepted, there have been many other PEPs that added
132+
new features to the Python type system. In general, new features can
133+
be used in typeshed as soon as the PEP has been accepted and implemented
134+
and most type checkers support the new feature.
135+
136+
Accepted features that *cannot* yet be used in typeshed include:
137+
- [PEP 570](https://www.python.org/dev/peps/pep-0570/) (positional-only
138+
arguments): see [#4972](https://github.com/python/typeshed/issues/4972),
139+
use argument names prefixed with `__` instead
140+
- [PEP 585](https://www.python.org/dev/peps/pep-0585/) (builtin
141+
generics): see [#4820](https://github.com/python/typeshed/issues/4820),
142+
mostly supported but bugs remain for a few specific cases
143+
- [PEP 604](https://www.python.org/dev/peps/pep-0604/) (Union
144+
pipe operator): see [#4819](https://github.com/python/typeshed/issues/4819)
145+
- [PEP 612](https://www.python.org/dev/peps/pep-0612/) (ParamSpec):
146+
see [#4827](https://github.com/python/typeshed/issues/4827)
147+
- [PEP 613](https://www.python.org/dev/peps/pep-0613/) (TypeAlias):
148+
see [#4913](https://github.com/python/typeshed/issues/4913)
149+
150+
Supported features include:
151+
- [PEP 544](https://www.python.org/dev/peps/pep-0544/) (Protocol)
152+
- [PEP 586](https://www.python.org/dev/peps/pep-0586/) (Literal)
153+
- [PEP 591](https://www.python.org/dev/peps/pep-0591/) (Final/@final)
154+
- [PEP 589](https://www.python.org/dev/peps/pep-0589/) (TypedDict)
155+
- [PEP 647](https://www.python.org/dev/peps/pep-0647/) (TypeGuard):
156+
see [#5406](https://github.com/python/typeshed/issues/5406)
157+
158+
Features from the `typing` module that are not present in all
159+
supported Python 3 versions must be imported from `typing_extensions`
160+
instead in typeshed stubs. This currently affects:
161+
162+
- `Final` and `@final` (new in Python 3.8)
163+
- `Literal` (new in Python 3.8)
164+
- `SupportsIndex` (new in Python 3.8)
165+
- `TypedDict` (new in Python 3.8)
166+
- `TypeGuard` (new in Python 3.10)
167+
168+
An exception is `Protocol`: although it was added in Python 3.8, it
169+
can be used in stubs regardless of Python version.
170+
129171
### What to include
130172

131173
Stubs should include the complete interface (classes, functions,

0 commit comments

Comments
 (0)