Skip to content

Commit 962936a

Browse files
authored
State in README that we backport the 3.12 version of Protocol, runtime_checkable and various runtime-checkable protocols (#143)
1 parent d3719ac commit 962936a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ This module currently contains the following:
9292
- `TypedDict` (see [PEP 589](https://peps.python.org/pep-0589/))
9393
- `get_origin` (`typing_extensions` provides this function only in Python 3.7+)
9494
- `get_args` (`typing_extensions` provides this function only in Python 3.7+)
95+
- `SupportsIndex`
9596

9697
- In `typing` since Python 3.7
9798

@@ -126,6 +127,17 @@ This module currently contains the following:
126127
- `NamedTuple` (supports multiple inheritance with `Generic` since Python 3.11)
127128
- `TypeVar` (see PEPs [695](https://peps.python.org/pep-0695/) and [696](https://peps.python.org/pep-0696/))
128129

130+
The following runtime-checkable protocols have always been present in `typing`,
131+
but the `isinstance()` checks against the `typing_extensions` versions are much
132+
faster on Python <3.12:
133+
134+
- `SupportsInt`
135+
- `SupportsFloat`
136+
- `SupportsComplex`
137+
- `SupportsBytes`
138+
- `SupportsAbs`
139+
- `SupportsRound`
140+
129141
# Other Notes and Limitations
130142

131143
Certain objects were changed after they were added to `typing`, and
@@ -156,6 +168,16 @@ Certain objects were changed after they were added to `typing`, and
156168
- `TypeVar` gains two additional parameters, `default=` and `infer_variance=`,
157169
in the draft PEPs [695](https://peps.python.org/pep-0695/) and [696](https://peps.python.org/pep-0696/), which are being considered for inclusion
158170
in Python 3.12.
171+
- `Protocol` was added in Python 3.8, but several bugfixes have been made in
172+
subsequent releases, as well as significant performance improvements to
173+
runtime-checkable protocols in Python 3.12. `typing_extensions` backports the
174+
3.12+ version to Python 3.7+.
175+
- `SupportsInt`, `SupportsFloat`, `SupportsComplex`, `SupportsBytes`,
176+
`SupportsAbs` and `SupportsRound` have always been present in the `typing`
177+
module. Meanwhile, `SupportsIndex` was added in Python 3.8. However,
178+
`isinstance()` checks against all these protocols were sped up significantly
179+
on Python 3.12. `typing_extensions` backports the faster versions to Python
180+
3.7+.
159181
- `Literal` does not flatten or deduplicate parameters on Python <3.9.1, and a
160182
caching bug was fixed in 3.10.1/3.9.8. The `typing_extensions` version
161183
flattens and deduplicates parameters on all Python versions, and the caching

0 commit comments

Comments
 (0)