Skip to content

Commit b89e2fa

Browse files
authored
Update protocol docs (python#7383)
This PR: * Adds a mention that `Protocol` is available in `typing` starting with Python 3.8. * Renames `@runtime` to `@runtime_checkable`.
1 parent eeb32dd commit b89e2fa

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

docs/source/protocols.rst

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ be used in ``with`` and ``async with`` statements.
254254
Simple user-defined protocols
255255
*****************************
256256
257-
You can define your own protocol class by inheriting the special
258-
``typing_extensions.Protocol`` class:
257+
You can define your own protocol class by inheriting the special ``Protocol``
258+
class:
259259
260260
.. code-block:: python
261261
@@ -284,10 +284,9 @@ similarly compatible with the protocol, as they support ``close()``.
284284
285285
.. note::
286286
287-
The ``Protocol`` base class is currently provided in the ``typing_extensions``
288-
package. Once structural subtyping is mature and
289-
`PEP 544 <https://www.python.org/dev/peps/pep-0544/>`_ has been accepted,
290-
``Protocol`` will be included in the ``typing`` module.
287+
The ``Protocol`` base class is provided in the ``typing_extensions``
288+
package for Python 2.7 and 3.4-3.7. Starting with Python 3.8, ``Protocol``
289+
is included in the ``typing`` module.
291290
292291
Defining subprotocols and subclassing protocols
293292
***********************************************
@@ -319,8 +318,8 @@ and merged using multiple inheritance. Example:
319318
Note that inheriting from an existing protocol does not automatically
320319
turn the subclass into a protocol -- it just creates a regular
321320
(non-protocol) class or ABC that implements the given protocol (or
322-
protocols). The ``typing_extensions.Protocol`` base class must always
323-
be explicitly present if you are defining a protocol:
321+
protocols). The ``Protocol`` base class must always be explicitly
322+
present if you are defining a protocol:
324323
325324
.. code-block:: python
326325
@@ -383,14 +382,14 @@ Using ``isinstance()`` with protocols
383382
*************************************
384383
385384
You can use a protocol class with ``isinstance()`` if you decorate it
386-
with the ``typing_extensions.runtime`` class decorator. The decorator
387-
adds support for basic runtime structural checks:
385+
with the ``@runtime_checkable`` class decorator. The decorator adds
386+
support for basic runtime structural checks:
388387
389388
.. code-block:: python
390389
391-
from typing_extensions import Protocol, runtime
390+
from typing_extensions import Protocol, runtime_checkable
392391
393-
@runtime
392+
@runtime_checkable
394393
class Portable(Protocol):
395394
handles: int
396395

0 commit comments

Comments
 (0)