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

Miscellaneous improvements to the typing docs #105529

Merged
merged 9 commits into from Jun 9, 2023

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Jun 8, 2023

Mostly, these are changes so that we use shorter sentences and shorter paragraphs. In particular, I've tried to make the first sentence introducing each object in the typing API short and declarative.

Also, among other things:

  • Use PEP-695 syntax in more places, including the docstring for Generic(!)
  • Three other changes to the docstrings in typevarobject.c:
    • Make indentation in the code examples consistent
    • Consistently use :: to introduce code examples, so that they render properly in IDE tooltips.
    • Shorter, and more even, line lengths for the docstrings. The uneven lengths we have currently makes them look quite odd when they're rendered in the REPL.
  • Fix a SyntaxError in a code example in the docstring for LiteralString
  • Use "OK" consistently, instead of "Ok" and "ok"
  • Add some examples to the docs for Required and NotRequired. The docstrings for these special forms are currently much more informative than the docs. Although the docs do link to the docs for TypedDict, where there's more information, I don't see any reason why we shouldn't put information where users will expect to find it.

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

Comment on lines -161 to -163
Note that ``None`` as a type hint is a special case and is replaced by
``type(None)``.

Copy link
Member Author

Choose a reason for hiding this comment

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

This just doesn't fit in this section at all. Even if it did, it's incorrect: None is treated more like Literal[None] than NoneType in terms of typing

Doc/library/typing.rst Outdated Show resolved Hide resolved
@AlexWaygood AlexWaygood added needs backport to 3.11 bug and security fixes needs backport to 3.12 bug and security fixes labels Jun 8, 2023
Doc/library/typing.rst Outdated Show resolved Hide resolved
Doc/library/typing.rst Outdated Show resolved Hide resolved
Doc/library/typing.rst Outdated Show resolved Hide resolved
@AlexWaygood
Copy link
Member Author

I changed my mind about adding examples to the API references for Required and NotRequired. They would have duplicated the information in the entry for TypedDict too much.

The better solution for this problem is for TypedDict, Required and NotRequired to all link to a "TypedDict HOWTO"-style document. I plan on working on that shortly.

@AlexWaygood AlexWaygood enabled auto-merge (squash) June 9, 2023 14:40
Doc/library/typing.rst Outdated Show resolved Hide resolved
@AlexWaygood AlexWaygood merged commit 8e75592 into python:main Jun 9, 2023
21 checks passed
@miss-islington
Copy link
Contributor

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

@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 8e755923c97d689ba7c7fe8deb50c1b169263264 3.11

@bedevere-bot
Copy link

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

@bedevere-bot bedevere-bot removed the needs backport to 3.12 bug and security fixes label Jun 9, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 9, 2023
Mostly, these are changes so that we use shorter sentences and shorter paragraphs. In particular, I've tried to make the first sentence introducing each object in the typing API short and declarative.
(cherry picked from commit 8e755923c97d689ba7c7fe8deb50c1b169263264)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@AlexWaygood AlexWaygood deleted the misc-typing-docs branch June 9, 2023 15:09
AlexWaygood added a commit to AlexWaygood/cpython that referenced this pull request Jun 9, 2023
Mostly, these are changes so that we use shorter sentences and shorter paragraphs. In particular, I've tried to make the first sentence introducing each object in the typing API short and declarative.
@bedevere-bot
Copy link

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

@bedevere-bot bedevere-bot removed the needs backport to 3.11 bug and security fixes label Jun 9, 2023
AlexWaygood added a commit that referenced this pull request Jun 9, 2023
 1�75567)

Miscellaneous improvements to the typing docs (GH-105529)

Mostly, these are changes so that we use shorter sentences and shorter paragraphs. In particular, I've tried to make the first sentence introducing each object in the typing API short and declarative.
(cherry picked from commit 8e75592)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
AlexWaygood added a commit that referenced this pull request Jun 9, 2023
Miscellaneous improvements to the typing docs (#105529)

Mostly, these are changes so that we use shorter sentences and shorter paragraphs. In particular, I've tried to make the first sentence introducing each object in the typing API short and declarative.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants