]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-42010: [docs] Clarify subscription of types (GH-22822)
authorkj <28750310+Fidget-Spinner@users.noreply.github.com>
Tue, 20 Oct 2020 23:38:08 +0000 (07:38 +0800)
committerGitHub <noreply@github.com>
Tue, 20 Oct 2020 23:38:08 +0000 (16:38 -0700)
Doc/reference/expressions.rst
Misc/NEWS.d/next/Documentation/2020-10-21-02-21-14.bpo-42010.76vJ0u.rst [new file with mode: 0644]

index 81dd6fc860355fbab8e004794fb381db6d14b44e..938a9732f5a250a782141fa6a788d545c4b9ef85 100644 (file)
@@ -800,8 +800,8 @@ Subscriptions
    object: dictionary
    pair: sequence; item
 
-A subscription selects an item of a sequence (string, tuple or list) or mapping
-(dictionary) object:
+Subscription of a sequence (string, tuple or list) or mapping (dictionary)
+object usually selects an item from the collection:
 
 .. productionlist:: python-grammar
    subscription: `primary` "[" `expression_list` "]"
@@ -837,6 +837,17 @@ this method will need to explicitly add that support.
 A string's items are characters.  A character is not a separate data type but a
 string of exactly one character.
 
+..
+   At the time of writing this, there is no documentation for generic alias
+   or PEP 585.  Thus the link currently points to PEP 585 itself.
+   Please change the link for generic alias to reference the correct
+   documentation once documentation for PEP 585 becomes available.
+
+Subscription of certain :term:`classes <class>` or :term:`types <type>`
+creates a `generic alias <https://www.python.org/dev/peps/pep-0585/>`_.
+In this case, user-defined classes can support subscription by providing a
+:meth:`__class_getitem__` classmethod.
+
 
 .. _slicings:
 
diff --git a/Misc/NEWS.d/next/Documentation/2020-10-21-02-21-14.bpo-42010.76vJ0u.rst b/Misc/NEWS.d/next/Documentation/2020-10-21-02-21-14.bpo-42010.76vJ0u.rst
new file mode 100644 (file)
index 0000000..2a0cbf1
--- /dev/null
@@ -0,0 +1,4 @@
+Clarify that subscription expressions are also valid for certain
+:term:`classes <class>` and :term:`types <type>` in the standard library, and
+for user-defined classes and types if the classmethod
+:meth:`__class_getitem__` is provided.