GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-45680: Improve docs on subscriptions w.r.t. `GenericAlias` objects by AlexWaygood · Pull Request #29479 · python/cpython

Conversation

@AlexWaygood

@AlexWaygood AlexWaygood commented Nov 8, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This PR is part of the project to improve documentation on GenericAlias objects and __class_getitem__, started in #29335.

https://bugs.python.org/issue45680

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@AlexWaygood
Improve docs on 'subscriptions'
5ae81b5
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Nov 8, 2021
@bedevere-bot bedevere-bot added docs Documentation in the Doc dir awaiting review labels Nov 8, 2021
@AlexWaygood AlexWaygood mentioned this pull request Nov 8, 2021
bpo-45680: Clarify documentation on GenericAlias objects #29335
Merged
AlexWaygood added 2 commits November 19, 2021 00:04
@AlexWaygood
Merge remote-tracking branch 'origin/main' into subscription-docs
0dfaee5
@AlexWaygood
Make this mergeable
f3d66fc
@AlexWaygood
AlexWaygood marked this pull request as ready for review November 19, 2021 00:26
@AlexWaygood
Reduce diff
46f96c0
@AlexWaygood AlexWaygood changed the title bpo-45680: Improve docs on 'subscriptions' bpo-45680: Improve docs on 'subscriptions' w.r.t. GenericAlias objects Dec 4, 2021
@AlexWaygood AlexWaygood changed the title bpo-45680: Improve docs on 'subscriptions' w.r.t. GenericAlias objects bpo-45680: Improve docs on 'subscriptions' w.r.t. GenericAlias objects Dec 4, 2021
@AlexWaygood AlexWaygood added needs backport to 3.9 skip news labels Dec 6, 2021
@AlexWaygood
Improve markup readability
dc77393
@AlexWaygood AlexWaygood changed the title bpo-45680: Improve docs on 'subscriptions' w.r.t. GenericAlias objects bpo-45680: Improve docs on subscriptions w.r.t. GenericAlias objects Dec 6, 2021
JelleZijlstra
JelleZijlstra approved these changes Jan 25, 2022
View reviewed changes
@bedevere-bot bedevere-bot added awaiting core review and removed awaiting review labels Jan 25, 2022
@AlexWaygood
AlexWaygood requested a review from Fidget-Spinner January 30, 2022 23:58
@AlexWaygood

AlexWaygood commented Feb 17, 2022

Copy link
Copy Markdown
Member Author

@JelleZijlstra, reckon this can be merged soon? :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra JelleZijlstra self-assigned this Feb 17, 2022
@JelleZijlstra

JelleZijlstra commented Feb 19, 2022

Copy link
Copy Markdown
Member

Looking at this again I'm not so sure, sorry. This adds more text than was there before, but the new text is a little repetitive. I do like the additional links though.

I feel like a broader problem with the language reference is that it veers too much into describing how concrete built-in types handle an operation, and not enough into how exactly the operation works. Here, for example, there is no precise description of when __class_getitem__ is called instead of __getitem__. That description exists only in the docs for __class_getitem__, but logically it should be part of the description of the subscript operator. The fact that the key is a tuple unless there is exactly one element shows up in a parenthetical in the text around mappings. (It's also wrong: obj[1,] is a tuple key, not an integer. The next section on slicing gets this right.) Also, type[int] works through deep magic in the interpreter, since type has neither a __getitem__ nor a __class_getitem__ magic, but nothing in the reference mentions this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra

JelleZijlstra commented Feb 19, 2022 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

See also bpo-46754.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood

AlexWaygood commented Feb 19, 2022

Copy link
Copy Markdown
Member Author

Looking at this again I'm not so sure, sorry.

Thanks for taking a look! I'll have a think tomorrow about whether I want to try revising this PR, or just close it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood
Merge remote-tracking branch 'origin/main' into subscription-docs
4ce0cb7
@AlexWaygood

AlexWaygood commented Mar 5, 2022

Copy link
Copy Markdown
Member Author

Here, for example, there is no precise description of when __class_getitem__ is called instead of __getitem__. That description exists only in the docs for __class_getitem__, but logically it should be part of the description of the subscript operator.

Perhaps you're right that that information might be better found in this document, but tbqh I don't have the energy to move that section from the data model to here after spending so long adding that section to the data model in GH-29389 :(

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood
Make more concise, improve technical accuracy
5393008
@AlexWaygood
AlexWaygood requested a review from JelleZijlstra March 5, 2022 23:04
@AlexWaygood

AlexWaygood commented Mar 5, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

@JelleZijlstra I've had another bash at it. I've tried to make the section less repetitive and increase the accuracy of the section regarding the "expression list".

The core aims of this PR are to:

  1. Make more prominent mention of the fact that subscriptions can also result in __class_getitem__ being called, as well as __getitem__.
  2. Add more links to to docs elsewhere on __class_getitem__.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood
tweaks
19edeef
JelleZijlstra
JelleZijlstra reviewed Mar 6, 2022
View reviewed changes

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

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.

Thanks! Just one comment.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/reference/expressions.rst

Subscription of a sequence (string, tuple or list) or mapping (dictionary)
object usually selects an item from the collection:
The subscription of an instance of a :ref:`container class <sequence-types>`

@JelleZijlstra JelleZijlstra Mar 6, 2022

Copy link
Copy Markdown
Member

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.

Seems weird to link this to sequence types. Maybe just drop the link? The later explanation is clearer about sequences and mappings.

Suggested change
The subscription of an instance of a :ref:`container class <sequence-types>`
The subscription of an instance of a container class

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@AlexWaygood AlexWaygood Mar 6, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

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 think the section in the docs linked to with sequence-types perhaps originally only discussed sequence types. Now, however, it discusses all kinds of container types -- the link takes us to here: https://docs.python.org/3/reference/datamodel.html#emulating-container-types

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JelleZijlstra reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
JelleZijlstra
JelleZijlstra approved these changes Mar 6, 2022
View reviewed changes

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

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.

Thanks! I'm happy to merge this now (cc @gvanrossum).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AlexWaygood reacted with heart emoji AlexWaygood reacted with rocket emoji
All reactions
  • ❤️ 1 reaction
  • 🚀 1 reaction
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Mar 6, 2022
gvanrossum
gvanrossum approved these changes Mar 6, 2022
View reviewed changes

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

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.

(Because the other meaning of "subscription" (e.g. a magazine) is so much more common I have a slight problem with using it to refer to the a[i] syntax, but it seems commonly used in our docs so it's fine. And the unambiguous alternative, "subscripting", is used much less frequently in our docs.)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AlexWaygood reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@JelleZijlstra
JelleZijlstra merged commit 5073129 into python:main Mar 8, 2022
@miss-islington

miss-islington commented Mar 8, 2022

Copy link
Copy Markdown
Contributor

Thanks @AlexWaygood for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed awaiting merge needs backport to 3.10 labels Mar 8, 2022
@bedevere-bot

bedevere-bot commented Mar 8, 2022

Copy link
Copy Markdown

GH-31743 is a backport of this pull request to the 3.10 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the needs backport to 3.9 label Mar 8, 2022
@bedevere-bot

bedevere-bot commented Mar 8, 2022

Copy link
Copy Markdown

GH-31744 is a backport of this pull request to the 3.9 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 8, 2022
@AlexWaygood @miss-islington
bpo-45680: Improve docs on subscriptions w.r.t. GenericAlias objects (
e1aa916
pythonGH-29479)

(cherry picked from commit 5073129)

Co-authored-by: Alex Waygood <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 8, 2022
@AlexWaygood @miss-islington
bpo-45680: Improve docs on subscriptions w.r.t. GenericAlias objects (
ac67130
pythonGH-29479)

(cherry picked from commit 5073129)

Co-authored-by: Alex Waygood <[email protected]>
miss-islington added a commit to miss-islington/cpython that referenced this pull request Mar 8, 2022
@miss-islington @AlexWaygood
bpo-45680: Improve docs on subscriptions w.r.t. GenericAlias objects (
06108c0
pythonGH-29479)

(cherry picked from commit 5073129)

Co-authored-by: Alex Waygood <[email protected]>
miss-islington added a commit that referenced this pull request Mar 8, 2022
@miss-islington @AlexWaygood
bpo-45680: Improve docs on subscriptions w.r.t. GenericAlias objects (
e83f084
GH-29479)

(cherry picked from commit 5073129)

Co-authored-by: Alex Waygood <[email protected]>
@AlexWaygood
AlexWaygood deleted the subscription-docs branch March 8, 2022 07:56
@AlexWaygood

AlexWaygood commented Mar 8, 2022

Copy link
Copy Markdown
Member Author

Thanks so much for helping get this over the line @JelleZijlstra!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hello-adam pushed a commit to hello-adam/cpython that referenced this pull request Jun 2, 2022
@miss-islington @AlexWaygood @hello-adam
bpo-45680: Improve docs on subscriptions w.r.t. GenericAlias objects (
f5675ae
pythonGH-29479)

(cherry picked from commit 5073129)

Co-authored-by: Alex Waygood <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@JelleZijlstra JelleZijlstra JelleZijlstra approved these changes
@gvanrossum gvanrossum gvanrossum approved these changes
@Fidget-Spinner Fidget-Spinner Awaiting requested review from Fidget-Spinner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@JelleZijlstra JelleZijlstra

Labels

docs Documentation in the Doc dir skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@AlexWaygood @JelleZijlstra @miss-islington @bedevere-bot @gvanrossum @the-knights-who-say-ni
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.