https://github.com/python/cpython/commit/f9578dc31fec95e0bf33ba2214554592182202f8 commit: f9578dc31fec95e0bf33ba2214554592182202f8 branch: 3.13 author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com> committer: AlexWaygood <alex.wayg...@gmail.com> date: 2025-04-16T17:50:31Z summary:
[3.13] typing docs: Clarify Protocol / runtime_checkable docs (GH-132606) (#132607) Co-authored-by: Jelle Zijlstra <jelle.zijls...@gmail.com> Co-authored-by: Alex Waygood <alex.wayg...@gmail.com> files: M Doc/library/typing.rst diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 0ce2c52a0c670e..bba7114fc1ff33 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -2353,7 +2353,8 @@ types. See :pep:`544` for more details. Protocol classes decorated with :func:`runtime_checkable` (described later) act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their - type signatures. + type signatures. Protocol classes without this decorator cannot be used + as the second argument to :func:`isinstance` or :func:`issubclass`. Protocol classes can be generic, for example:: @@ -2377,8 +2378,7 @@ types. Mark a protocol class as a runtime protocol. Such a protocol can be used with :func:`isinstance` and :func:`issubclass`. - This raises :exc:`TypeError` when applied to a non-protocol class. This - allows a simple-minded structural check, very similar to "one trick ponies" + This allows a simple-minded structural check, very similar to "one trick ponies" in :mod:`collections.abc` such as :class:`~collections.abc.Iterable`. For example:: @runtime_checkable @@ -2394,6 +2394,8 @@ types. import threading assert isinstance(threading.Thread(name='Bob'), Named) + This decorator raises :exc:`TypeError` when applied to a non-protocol class. + .. note:: :func:`!runtime_checkable` will check only the presence of the required _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com