-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
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>
| >>> demo[1, 2, 3] | ||
| subscripted with (1, 2, 3) | ||
| >>> demo[1:2, 3] | ||
| subscripted with (slice(1, 2, None), 3) |
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.
I find using examples that require bits from several examples ago and are in a different section a tad odd. We are also missing colons.
| by a comma, to specify a one-element tuple:: | ||
|
|
||
| >>> demo['spam',] | ||
| subscripted with ('spam',) |
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.
Same issue as above.
| >>> number_names[:] | ||
| ['zero', 'one', 'two'] | ||
| >>> number_names[::2] | ||
| ['zero', 'two', 'four'] |
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.
Maybe add an example of a negative index here (the more the merrier ;-)?
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.
And deletion perhaps? :-3
| ['zero', 'two', 'four'] | |
| ['zero', 'two', 'four'] | |
| >>> number_names[:-3] | |
| ['zero', 'one', 'two'] | |
| >>> del number_names[4:] | |
| >>> number_names | |
| ['zero', 'one', 'two', 'three'] |
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.
And deletion perhaps? :-3
My previous comment still applies :-)
Doc/reference/expressions.rst
Outdated
| Subscriptions and slicing | ||
| ------------------------- |
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.
| Subscriptions and slicing | |
| ------------------------- | |
| Subscription and slicing | |
| ------------------------ |
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.
All the other section names are plural¹. What do you think about continuing that?
| Subscriptions and slicing | |
| ------------------------- | |
| Subscriptions and slicings | |
| -------------------------- |
¹ except about two, let's fix them when their time comes?
Doc/reference/expressions.rst
Outdated
| Tuple subscription | ||
| ^^^^^^^^^^^^^^^^^^ |
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.
To me, this sounds like a section about subscripting tuples specifically. Maybe "Comma-separated subscription" instead?
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.
| Tuple subscription | |
| ^^^^^^^^^^^^^^^^^^ | |
| Comma-separated subscripts | |
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ |
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!
Doc/reference/expressions.rst
Outdated
| Subscriptions and slicing | ||
| ------------------------- |
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.
All the other section names are plural¹. What do you think about continuing that?
| Subscriptions and slicing | |
| ------------------------- | |
| Subscriptions and slicings | |
| -------------------------- |
¹ except about two, let's fix them when their time comes?
| >>> number_names[:] | ||
| ['zero', 'one', 'two'] | ||
| >>> number_names[::2] | ||
| ['zero', 'two', 'four'] |
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.
And deletion perhaps? :-3
| ['zero', 'two', 'four'] | |
| ['zero', 'two', 'four'] | |
| >>> number_names[:-3] | |
| ['zero', 'one', 'two'] | |
| >>> del number_names[4:] | |
| >>> number_names | |
| ['zero', 'one', 'two', 'three'] |
Doc/reference/expressions.rst
Outdated
| Tuple subscription | ||
| ^^^^^^^^^^^^^^^^^^ |
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.
| Tuple subscription | |
| ^^^^^^^^^^^^^^^^^^ | |
| Comma-separated subscripts | |
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| >>> demo[1, 2, 3] | ||
| subscripted with (1, 2, 3) | ||
| >>> demo[1:2, 3] | ||
| subscripted with (slice(1, 2, None), 3) |
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.
I find using examples that require bits from several examples ago and are in a different section a tad odd.
True, but the SubscriptionDemo is a bit too big to define every time it's used. Would the following work? (added whenever demo is first used in a section).
| >>> demo[1, 2, 3] | |
| subscripted with (1, 2, 3) | |
| >>> demo[1:2, 3] | |
| subscripted with (slice(1, 2, None), 3) | |
| # continuing with the SubscriptionDemo instance defined above: | |
| >>> demo[1, 2, 3] | |
| subscripted with (1, 2, 3) | |
| >>> demo[1:2, 3] | |
| subscripted with (slice(1, 2, None), 3) |
We are also missing colons.
What do you mean?
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.
What do you mean?
Like in my above comments, the demo actually prints subscripted with: and not subscripted with .
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.
True, but the SubscriptionDemo is a bit too big to define every time it's used. Would the following work? (added whenever demo is first used in a section).
I agree, this is also a bit like the issue with imports. The comment is an improvement, although still not ideal.
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/