Skip to content

bpo-42010: [docs] Clarify subscription of types #22822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 20, 2020
Merged
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
15 changes: 13 additions & 2 deletions Doc/reference/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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` "]"
Expand Down Expand Up @@ -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:

Expand Down
Original file line number Diff line number Diff line change
@@ -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.