Skip to content

Commit 7cdf30f

Browse files
bpo-42010: [docs] Clarify subscription of types (GH-22822)
1 parent 2d55aa9 commit 7cdf30f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Doc/reference/expressions.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,8 @@ Subscriptions
800800
object: dictionary
801801
pair: sequence; item
802802

803-
A subscription selects an item of a sequence (string, tuple or list) or mapping
804-
(dictionary) object:
803+
Subscription of a sequence (string, tuple or list) or mapping (dictionary)
804+
object usually selects an item from the collection:
805805

806806
.. productionlist:: python-grammar
807807
subscription: `primary` "[" `expression_list` "]"
@@ -837,6 +837,17 @@ this method will need to explicitly add that support.
837837
A string's items are characters. A character is not a separate data type but a
838838
string of exactly one character.
839839

840+
..
841+
At the time of writing this, there is no documentation for generic alias
842+
or PEP 585. Thus the link currently points to PEP 585 itself.
843+
Please change the link for generic alias to reference the correct
844+
documentation once documentation for PEP 585 becomes available.
845+
846+
Subscription of certain :term:`classes <class>` or :term:`types <type>`
847+
creates a `generic alias <https://www.python.org/dev/peps/pep-0585/>`_.
848+
In this case, user-defined classes can support subscription by providing a
849+
:meth:`__class_getitem__` classmethod.
850+
840851

841852
.. _slicings:
842853

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Clarify that subscription expressions are also valid for certain
2+
:term:`classes <class>` and :term:`types <type>` in the standard library, and
3+
for user-defined classes and types if the classmethod
4+
:meth:`__class_getitem__` is provided.

0 commit comments

Comments
 (0)