-
-
Notifications
You must be signed in to change notification settings - Fork 34k
gh-141984: Reword and reorganize Subscription (and Slicing) docs #141985
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Blaise Pabon <blaise@gmail.com>
Co-authored-by: Blaise Pabon <blaise@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Blaise Pabon <blaise@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
encukou
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for going through this!
StanFromIreland
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few little things, overall looks very good!
| the ``3`` in ``items[3]``. | ||
| Usually used to select an element of a container. | ||
| Also called a :term:`key` when subscripting a :term:`mapping`, | ||
| or :term:`index` when subscripting a :term:`sequence`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| or :term:`index` when subscripting a :term:`sequence`. | |
| or an :term:`index` when subscripting a :term:`sequence`. |
| subscription: `primary` '[' `subscript` ']' | ||
| subscript: `slice` | `tuple_slices` | ||
| tuple_slices: ','.(`slice` | `starred_expression`)+ [','] | ||
| slice: `proper_slice` | `assignment_expression` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By this grammar, if one does something[0], 0 is an int and is a slice, but that contradicts with your glossary entry, that states it must be a "an object of type slice"?
| Note that no error is raised if a slice position is less than zero or larger | ||
| than the length of the sequence. | ||
|
|
||
| If *start* is missing or ``None``, slicing behaves as if *start* was zero. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| If *start* is missing or ``None``, slicing behaves as if *start* was zero. | |
| If *start* is missing or :data:`None`, slicing behaves as if *start* was zero. |
This merges the Subscriptions and Slicings sections in the language reference. From the parser's point of view, slicing is a special case of subscription, and it makes sense to document it that way too.
The PR also touches Data model documentation: I've tried to move details of the runtime behaviour there, and to de-duplicate (and cross-link) as needed.
Similar for the
sliceattribute docs.Todo:
📚 Documentation preview 📚: https://cpython-previews--141985.org.readthedocs.build/