Skip to content

typing: Improve documentation of generic classes and aliases #105369

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 6 commits into from
Jun 7, 2023

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Jun 6, 2023

The documentation for typing.Dict currently describes the alias as:

A generic version of :class:dict.

In 2023, this is pretty misleading: it implies that dict is not generic, and that you have to use typing.Dict if you want to supply type parameters. There are similar issues across the typing documentation for the various aliases that were deprecated as part of PEP-585.

This PR also makes a few related edits to the docs for generic classes, which look like they still have some pre-PEP-585 language in them.


📚 Documentation preview 📚: https://cpython-previews--105369.org.readthedocs.build/

Comment on lines 322 to 323
def second(l: Sequence[U]) -> U: # Function is generic around the TypeVar "U"
return l[1]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured it was slightly confusing to have two functions named first in two adjacent code examples

@AlexWaygood AlexWaygood changed the title typing: Improve documentation of generic classes typing: Improve documentation of generic classes and aliases Jun 6, 2023
@AlexWaygood
Copy link
Member Author

@AlexWaygood AlexWaygood requested a review from JelleZijlstra June 7, 2023 08:26
@AlexWaygood AlexWaygood enabled auto-merge (squash) June 7, 2023 13:44
@AlexWaygood AlexWaygood merged commit d63a7c3 into python:main Jun 7, 2023
@miss-islington
Copy link
Contributor

Thanks @AlexWaygood for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @AlexWaygood, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker d63a7c3694d5c4484fcaa01c33590b1d4bc2559e 3.11

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 7, 2023
@bedevere-bot
Copy link

GH-105453 is a backport of this pull request to the 3.12 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.12 only security fixes label Jun 7, 2023
@AlexWaygood AlexWaygood deleted the deprecated-aliases branch June 7, 2023 14:03
AlexWaygood added a commit to AlexWaygood/cpython that referenced this pull request Jun 7, 2023
@bedevere-bot
Copy link

GH-105454 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Jun 7, 2023
AlexWaygood added a commit that referenced this pull request Jun 7, 2023
…H-105369) (#105453)

typing: Improve documentation of generic classes and aliases (GH-105369)
(cherry picked from commit d63a7c3)

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants