[Python-checkins] [3.9] bpo-42010: [docs] Clarify subscription of types (GH-22822) (GH-22840)
miss-islington
webhook-mailer at python.org
Tue Oct 20 19:58:57 EDT 2020
https://github.com/python/cpython/commit/d05514ace652769457e6228f0186d4f830b676b9
commit: d05514ace652769457e6228f0186d4f830b676b9
branch: 3.9
author: Miss Skeleton (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2020-10-20T16:58:49-07:00
summary:
[3.9] bpo-42010: [docs] Clarify subscription of types (GH-22822) (GH-22840)
(cherry picked from commit 7cdf30fff39ea97f403b5472096349998d190e30)
Co-authored-by: kj <28750310+Fidget-Spinner at users.noreply.github.com>
Automerge-Triggered-By: GH:gvanrossum
files:
A Misc/NEWS.d/next/Documentation/2020-10-21-02-21-14.bpo-42010.76vJ0u.rst
M Doc/reference/expressions.rst
diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst
index b68c29860cf33..f1f19c3f02d39 100644
--- a/Doc/reference/expressions.rst
+++ b/Doc/reference/expressions.rst
@@ -796,8 +796,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` "]"
@@ -833,6 +833,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
index 0000000000000..2a0cbf1075783
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2020-10-21-02-21-14.bpo-42010.76vJ0u.rst
@@ -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.
More information about the Python-checkins
mailing list