Skip to content

Commit f9578dc

Browse files
miss-islingtonJelleZijlstraAlexWaygood
authored
[3.13] typing docs: Clarify Protocol / runtime_checkable docs (GH-132606) (#132607)
Co-authored-by: Jelle Zijlstra <[email protected]> Co-authored-by: Alex Waygood <[email protected]>
1 parent 88d95c3 commit f9578dc

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Doc/library/typing.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,8 @@ types.
23532353
See :pep:`544` for more details. Protocol classes decorated with
23542354
:func:`runtime_checkable` (described later) act as simple-minded runtime
23552355
protocols that check only the presence of given attributes, ignoring their
2356-
type signatures.
2356+
type signatures. Protocol classes without this decorator cannot be used
2357+
as the second argument to :func:`isinstance` or :func:`issubclass`.
23572358

23582359
Protocol classes can be generic, for example::
23592360

@@ -2377,8 +2378,7 @@ types.
23772378
Mark a protocol class as a runtime protocol.
23782379

23792380
Such a protocol can be used with :func:`isinstance` and :func:`issubclass`.
2380-
This raises :exc:`TypeError` when applied to a non-protocol class. This
2381-
allows a simple-minded structural check, very similar to "one trick ponies"
2381+
This allows a simple-minded structural check, very similar to "one trick ponies"
23822382
in :mod:`collections.abc` such as :class:`~collections.abc.Iterable`. For example::
23832383

23842384
@runtime_checkable
@@ -2394,6 +2394,8 @@ types.
23942394
import threading
23952395
assert isinstance(threading.Thread(name='Bob'), Named)
23962396

2397+
This decorator raises :exc:`TypeError` when applied to a non-protocol class.
2398+
23972399
.. note::
23982400

23992401
:func:`!runtime_checkable` will check only the presence of the required

0 commit comments

Comments
 (0)