Skip to content
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

bpo-42280: Clarify docs on standard generic collections #29308

Closed
wants to merge 3 commits into from

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Oct 29, 2021

This PR proposes adding two classes to the list of standard generic collections in the docs. These classes can be parametrised at runtime, but are currently omitted from the list.

The PR also tweaks the wording introducing the list, to make clear that the docs are not promising that this is an exhaustive list.

The PR does not add any of the classes from the queue module (queue.Queue, queue.LifoQueue, queue.PriorityQueue, queue.SimpleQueue), even though these can be parametrised. I have excluded these from the PR, as the documentation states that this is a list of "standard-library collections", and the queue classes are not collections (they are neither sized, nor iterable). However, re.Pattern is included in this list, and re.Pattern objects are also not collections -- so, perhaps the queue classes should also be added to this list.

https://bugs.python.org/issue42280

This PR proposes adding two classes to the list of standard generic collections in the docs. These classes can be parametrised at runtime, but are currently omitted from the list.

The PR also tweaks the wording introducing the list, to make clear that the docs are not promising that this is an exhaustive list.

The PR does not add any of the classes from the ``queue`` module (``queue.Queue``, ``queue.LifoQueue``, ``queue.PriorityQueue``, ``queue.SimpleQueue``), even though these can be parametrised. I have excluded these from the PR, as the documentation states that this is a list of "standard-library collections", and the ``queue`` classes are not collections (they are neither sized, nor iterable). However, ``re.Pattern`` is included in this list, and ``re.Pattern`` objects are also not collections -- so, perhaps the ``queue`` classes should also be added to this list.
@Fidget-Spinner
Copy link
Member

I would prefer we explicitly say "This list is non-exhaustive.". We won't be able to keep up with all the classes supporting __class_getitem__ as time goes by. There are way too many to list.

Related issue https://bugs.python.org/issue42280.

@AlexWaygood
Copy link
Member Author

I would prefer we explicitly say "This list is non-exhaustive.". We won't be able to keep up with all the classes supporting __class_getitem__ as time goes by. There are way too many to list.

Related issue https://bugs.python.org/issue42280.

Ah, apologies, I didn't realise there was already an issue on this. I just stumbled across the list while doing the PR for the typing documentation. I agree with the thoughts on the BPO thread -- I think it's much wiser to clarify that the list is non-exhaustive rather than to attempt to put together an exhaustive list. Have edited the PR.

@AlexWaygood AlexWaygood changed the title Clarify docs on standard generic collections bpo-42280: Clarify docs on standard generic collections Oct 29, 2021
@Fidget-Spinner
Copy link
Member

Ah, apologies, I didn't realise there was already an issue on this. I just stumbled across the list while doing the PR for the typing documentation. I agree with the thoughts on the BPO thread -- I think it's much wiser to clarify that the list is non-exhaustive rather than to attempt to put together an exhaustive list. Have edited the PR.

Yeah no issues (pun intended) there. I just linked the issue to provide some context behind our current stance. You don't have to link this PR to that (though I don't mind you linking it either :).

Doc/library/stdtypes.rst Outdated Show resolved Hide resolved
@ambv
Copy link
Contributor

ambv commented Oct 29, 2021

@AlexWaygood, now that I think about it, I think you're making a good point about "collections" not being "collections" in the list. How about we fix it by:

  • adding queue classes (and others if any come to your mind)
  • using the word data structures instead of collections in the wording of the list in question

@AlexWaygood
Copy link
Member Author

@AlexWaygood, now that I think about it, I think you're making a good point about "collections" not being "collections" in the list. How about we fix it by:

  • adding queue classes (and others if any come to your mind)
  • using the word data structures instead of collections in the wording of the list in question

...how are we defining "data structures"? 🤔 If re.Pattern belongs in this list, does os.PathLike?

I think I'd be tempted to split it into two lists: a list of standard library collections that can be parameterised, and a list of standard library ABCs that can be parameterised. We have widely agreed-upon definitions for what constitutes a "collection" and what constitutes an "ABC", so it would make this problem easier to tackle.

But I'm not sure the classes from the re module would belong in either list 🤷

@AlexWaygood
Copy link
Member Author

I'm going to close this PR and open a new one.

AlexWaygood added a commit to AlexWaygood/cpython that referenced this pull request Oct 30, 2021
The documentation on ``GenericAlias`` objects implies at multiple points that
only container classes can define ``__class_getitem__``. This is misleading.
This PR proposes a rewrite of the documentation to clarify that non-container
classes can define ``__class_getitem__``, and to clarify what it means when a
non-container class is parameterized.

See also: initial discussion of issues with this piece of documentation in
python#29308, and previous BPO issue [42280](https://bugs.python.org/issue42280).
@AlexWaygood AlexWaygood deleted the patch-1 branch October 30, 2021 20:47
Fidget-Spinner added a commit that referenced this pull request Jan 19, 2022
The documentation on ``GenericAlias`` objects implies at multiple points that
only container classes can define ``__class_getitem__``. This is misleading.
This PR proposes a rewrite of the documentation to clarify that non-container
classes can define ``__class_getitem__``, and to clarify what it means when a
non-container class is parameterized.

See also: initial discussion of issues with this piece of documentation in
GH-29308, and previous BPO issue [42280](https://bugs.python.org/issue42280).

Also improved references in glossary and typing docs. Fixed some links.

Co-authored-by: Erlend Egeberg Aasland <[email protected]>
Co-authored-by: Ken Jin <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 19, 2022
…H-29335)

The documentation on ``GenericAlias`` objects implies at multiple points that
only container classes can define ``__class_getitem__``. This is misleading.
This PR proposes a rewrite of the documentation to clarify that non-container
classes can define ``__class_getitem__``, and to clarify what it means when a
non-container class is parameterized.

See also: initial discussion of issues with this piece of documentation in
pythonGH-29308, and previous BPO issue [42280](https://bugs.python.org/issue42280).

Also improved references in glossary and typing docs. Fixed some links.

Co-authored-by: Erlend Egeberg Aasland <[email protected]>
Co-authored-by: Ken Jin <[email protected]>
(cherry picked from commit 0eae9a2)

Co-authored-by: Alex Waygood <[email protected]>
Fidget-Spinner added a commit to Fidget-Spinner/cpython that referenced this pull request Jan 19, 2022
…H-29335)

The documentation on ``GenericAlias`` objects implies at multiple points that
only container classes can define ``__class_getitem__``. This is misleading.
This PR proposes a rewrite of the documentation to clarify that non-container
classes can define ``__class_getitem__``, and to clarify what it means when a
non-container class is parameterized.

See also: initial discussion of issues with this piece of documentation in
pythonGH-29308, and previous BPO issue [42280](https://bugs.python.org/issue42280).

Also improved references in glossary and typing docs. Fixed some links.

Co-Authored-By: Erlend Egeberg Aasland <[email protected]>
Co-Authored-By: Ken Jin <[email protected]>
Co-Authored-By: Alex Waygood <[email protected]>
miss-islington added a commit that referenced this pull request Jan 19, 2022
…H-29335) (GH-30688)

The documentation on ``GenericAlias`` objects implies at multiple points that
only container classes can define ``__class_getitem__``. This is misleading.
This PR proposes a rewrite of the documentation to clarify that non-container
classes can define ``__class_getitem__``, and to clarify what it means when a
non-container class is parameterized.

See also: initial discussion of issues with this piece of documentation in
GH-29308, and previous BPO issue [42280]().

Also improved references in glossary and typing docs. Fixed some links.

Co-authored-by: Erlend Egeberg Aasland <[email protected]>
Co-authored-by: Ken Jin <[email protected]>
(cherry picked from commit 0eae9a2)


Co-authored-by: Alex Waygood <[email protected]>

Automerge-Triggered-By: GH:Fidget-Spinner
Fidget-Spinner added a commit that referenced this pull request Jan 19, 2022
…H-29335) (GH-30689)

The documentation on ``GenericAlias`` objects implies at multiple points that
only container classes can define ``__class_getitem__``. This is misleading.
This PR proposes a rewrite of the documentation to clarify that non-container
classes can define ``__class_getitem__``, and to clarify what it means when a
non-container class is parameterized.

See also: initial discussion of issues with this piece of documentation in
GH-29308, and previous BPO issue [42280](https://bugs.python.org/issue42280).

Also improved references in glossary and typing docs. Fixed some links.

(cherry picked from commit 0eae9a2)

Co-Authored-By: Erlend Egeberg Aasland <[email protected]>
Co-Authored-By: Ken Jin <[email protected]>
Co-Authored-By: Alex Waygood <[email protected]>
hello-adam pushed a commit to hello-adam/cpython that referenced this pull request Jun 2, 2022
…ythonGH-29335) (pythonGH-30689)

The documentation on ``GenericAlias`` objects implies at multiple points that
only container classes can define ``__class_getitem__``. This is misleading.
This PR proposes a rewrite of the documentation to clarify that non-container
classes can define ``__class_getitem__``, and to clarify what it means when a
non-container class is parameterized.

See also: initial discussion of issues with this piece of documentation in
pythonGH-29308, and previous BPO issue [42280](https://bugs.python.org/issue42280).

Also improved references in glossary and typing docs. Fixed some links.

(cherry picked from commit 0eae9a2)

Co-Authored-By: Erlend Egeberg Aasland <[email protected]>
Co-Authored-By: Ken Jin <[email protected]>
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
Labels
awaiting review docs Documentation in the Doc dir needs backport to 3.9 only security fixes needs backport to 3.10 only security fixes skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants