Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/spec/concepts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ is a subtype of ``str``, because ``MyStr`` represents a subset of the values
represented by ``str``. Such types can be called "nominal types" and this is
"nominal subtyping."

.. _`concrete-type`:

Concrete types
--------------

A **concrete type** is a type specified by the name of a Python class, for
example, ``int``, ``str``, ``list``, or any user-defined class. Concrete types
represent actual Python objects and are distinct from protocols, type
variables, or type forms. They are used in type annotations where a specific
class is intended.

Other types (e.g. :ref:`Protocols` and :ref:`TypedDict`) instead describe a set
of values by the types of their attributes and methods, or the types of their
dictionary keys and values. These are called "structural types". A structural
Expand Down
6 changes: 3 additions & 3 deletions docs/spec/protocol.rst
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ Protocols cannot be instantiated, so there are no values whose
runtime type is a protocol. For variables and parameters with protocol types,
assignability relationships are subject to the following rules:

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

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