Skip to content

Commit d05514a

Browse files
[3.9] bpo-42010: [docs] Clarify subscription of types (GH-22822) (GH-22840)
(cherry picked from commit 7cdf30f) Co-authored-by: kj <[email protected]> Automerge-Triggered-By: GH:gvanrossum
1 parent 46130f8 commit d05514a

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
@@ -796,8 +796,8 @@ Subscriptions
796796
object: dictionary
797797
pair: sequence; item
798798

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

802802
.. productionlist:: python-grammar
803803
subscription: `primary` "[" `expression_list` "]"
@@ -833,6 +833,17 @@ this method will need to explicitly add that support.
833833
A string's items are characters. A character is not a separate data type but a
834834
string of exactly one character.
835835

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

837848
.. _slicings:
838849

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)