Skip to content

Commit 26163af

Browse files
committed
docs: add concrete type definition and update protocol references
1 parent ecfd695 commit 26163af

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

docs/spec/concepts.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,17 @@ is a subtype of ``str``, because ``MyStr`` represents a subset of the values
169169
represented by ``str``. Such types can be called "nominal types" and this is
170170
"nominal subtyping."
171171

172+
.. _`concrete-type`:
173+
174+
Concrete types
175+
--------------
176+
177+
A **concrete type** is a type specified by the name of a Python class, for
178+
example, ``int``, ``str``, ``list``, or any user-defined class. Concrete types
179+
represent actual Python objects and are distinct from protocols, type
180+
variables, or type forms. They are used in type annotations where a specific
181+
class is intended.
182+
172183
Other types (e.g. :ref:`Protocols` and :ref:`TypedDict`) instead describe a set
173184
of values by the types of their attributes and methods, or the types of their
174185
dictionary keys and values. These are called "structural types". A structural

docs/spec/protocol.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,8 @@ Protocols cannot be instantiated, so there are no values whose
385385
runtime type is a protocol. For variables and parameters with protocol types,
386386
assignability relationships are subject to the following rules:
387387

388-
* A protocol is never assignable to a concrete type.
389-
* A concrete type ``X`` is assignable to a protocol ``P`` if and only if ``X``
388+
* A protocol is never assignable to a :ref:`concrete-type`.
389+
* A :ref:`concrete-type` ``X`` is assignable to a protocol ``P`` if and only if ``X``
390390
implements all protocol members of ``P`` with assignable types. In other
391391
words, :term:`assignability <assignable>` with respect to a protocol is
392392
always :term:`structural`.
@@ -465,7 +465,7 @@ Example::
465465
``type[]`` and class objects vs protocols
466466
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
467467

468-
Variables and parameters annotated with ``type[Proto]`` accept only concrete
468+
Variables and parameters annotated with ``type[Proto]`` accept only :ref:`concrete-types <concrete-type>`
469469
(non-protocol) :term:`consistent subtypes <consistent subtype>` of ``Proto``.
470470
The main reason for this is to allow instantiation of parameters with such
471471
types. For example::

0 commit comments

Comments
 (0)