Skip to content

Commit

Permalink
State in README that we backport the 3.12 version of Protocol, `run…
Browse files Browse the repository at this point in the history
…time_checkable` and various runtime-checkable protocols (#143)
  • Loading branch information
AlexWaygood authored Apr 26, 2023
1 parent d3719ac commit 962936a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ This module currently contains the following:
- `TypedDict` (see [PEP 589](https://peps.python.org/pep-0589/))
- `get_origin` (`typing_extensions` provides this function only in Python 3.7+)
- `get_args` (`typing_extensions` provides this function only in Python 3.7+)
- `SupportsIndex`

- In `typing` since Python 3.7

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

The following runtime-checkable protocols have always been present in `typing`,
but the `isinstance()` checks against the `typing_extensions` versions are much
faster on Python <3.12:

- `SupportsInt`
- `SupportsFloat`
- `SupportsComplex`
- `SupportsBytes`
- `SupportsAbs`
- `SupportsRound`

# Other Notes and Limitations

Certain objects were changed after they were added to `typing`, and
Expand Down Expand Up @@ -156,6 +168,16 @@ Certain objects were changed after they were added to `typing`, and
- `TypeVar` gains two additional parameters, `default=` and `infer_variance=`,
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
in Python 3.12.
- `Protocol` was added in Python 3.8, but several bugfixes have been made in
subsequent releases, as well as significant performance improvements to
runtime-checkable protocols in Python 3.12. `typing_extensions` backports the
3.12+ version to Python 3.7+.
- `SupportsInt`, `SupportsFloat`, `SupportsComplex`, `SupportsBytes`,
`SupportsAbs` and `SupportsRound` have always been present in the `typing`
module. Meanwhile, `SupportsIndex` was added in Python 3.8. However,
`isinstance()` checks against all these protocols were sped up significantly
on Python 3.12. `typing_extensions` backports the faster versions to Python
3.7+.
- `Literal` does not flatten or deduplicate parameters on Python <3.9.1, and a
caching bug was fixed in 3.10.1/3.9.8. The `typing_extensions` version
flattens and deduplicates parameters on all Python versions, and the caching
Expand Down

0 comments on commit 962936a

Please sign in to comment.