10000 bpo-45680: Improve docs on subscriptions w.r.t. `GenericAlias` objects by AlexWaygood · Pull Request #29479 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-45680: Improve docs on subscriptions w.r.t. GenericAlias objects #29479

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 8 commits into from
Mar 8, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Improve markup readability
  • Loading branch information
AlexWaygood authored Dec 6, 2021
commit dc77393a7207a18cfecd88cf621c98f34caa0a68
12 changes: 6 additions & 6 deletions Doc/reference/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -816,19 +816,19 @@ Subscriptions
pair: sequence; item

The subscription of an object in Python can have one of two effects. If the
object is a :term:`sequence` (such as a :class:`string<str>`,
object is a :term:`sequence` (such as a :class:`string <str>`,
:class:`tuple` or :class:`list`) or a :term:`mapping` (such as a
:class:`dictionary<dict>`), subscripting the object will select an object from
:class:`dictionary <dict>`), subscripting the object will select an object from
the collection. Subscripting certain *classes or types*, meanwhile, will
return a :ref:`generic alias <types-genericalias>` object representing a
*parameterized generic class*. The latter form of subscription is primarily
useful for :term:`type hinting<type hint>`.
useful for :term:`type hinting <type hint>`.

.. productionlist:: python-grammar
subscription: `primary` "[" `expression_list` "]"

The primary must evaluate to an object that supports subscription, such as a
:class:`list` or a :class:`dictionary<dict>`. User-defined objects can support
:class:`list` or a :class:`dictionary <dict>`. User-defined objects can support
subscription by defining one or both of :meth:`~object.__getitem__` and
:meth:`~object.__class_getitem__`.

Expand All @@ -852,7 +852,7 @@ via :meth:`~object.__getitem__`:
:class:`int` or a :class:`slice` (as discussed in the following section).

The formal syntax makes no special provision for negative indices in
:term:`sequences<sequence>`. However, built-in sequences all provide a :meth:`~object.__getitem__`
:term:`sequences <sequence>`. However, built-in sequences all provide a :meth:`~object.__getitem__`
method that interprets negative indices by adding the length of the sequence
to the index so that, for example, ``x[-1]`` selects the last item of ``x``. The
resulting value must be a nonnegative integer less than the number of items in
Expand All @@ -865,7 +865,7 @@ this method will need to explicitly add that support.
single: character
pair: string; item

A :class:`string<str>` is a special kind of sequence whose items are
A :class:`string <str>` is a special kind of sequence whose items are
*characters*. A character is not a separate data type but a string of exactly
one character.

Expand Down
0