-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Improve the typing docs #92264
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
Improve the typing docs #92264
Conversation
@@ -125,7 +125,7 @@ Note that ``None`` as a type hint is a special case and is replaced by | |||
NewType | |||
======= | |||
|
|||
Use the :class:`NewType` helper class to create distinct types:: | |||
Use the :class:`NewType` helper to create distinct types:: |
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.
It's an implementation detail whether it is a class or a function, so avoid being specific.
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.
An alternative would be "helper callable", but I think "helper" is also fine.
@@ -880,7 +880,6 @@ These can be used as types in annotations using ``[]``, each having a unique syn | |||
|
|||
def with_lock(f: Callable[Concatenate[Lock, P], R]) -> Callable[P, R]: | |||
'''A type-safe decorator which provides a lock.''' | |||
global my_lock |
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.
Not needed since we're not writing to the variable
@@ -1036,7 +1035,7 @@ These can be used as types in annotations using ``[]``, each having a unique syn | |||
``no_type_check`` functionality that currently exists in the ``typing`` | |||
module which completely disables typechecking annotations on a function | |||
or a class, the ``Annotated`` type allows for both static typechecking | |||
of ``T`` (e.g., via mypy or Pyre, which can safely ignore ``x``) | |||
of ``T`` (which can safely ignore ``x``) |
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.
No need to call out specific type checkers here
@@ -1695,7 +1694,7 @@ These are not used in annotations. They are building blocks for declaring types. | |||
in 3.13. It may also be unsupported by static type checkers. | |||
|
|||
The functional syntax should also be used when any of the keys are not valid | |||
:ref:`identifiers`, for example because they are keywords or contain hyphens. | |||
:ref:`identifiers <identifiers>`, for example because they are keywords or contain hyphens. |
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.
This showed up as "Identifiers and keywords" (the section title over there).
Co-authored-by: Alex Waygood <[email protected]>
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.
Wow there were a lot of markup errors.
Co-authored-by: Alex Waygood <[email protected]>
Here's a pdf of what the docs look like with these changes: typing — Support for type hints — Python 3.11.0a7 documentation.pdf |
Thanks @JelleZijlstra for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10. |
Sorry, @JelleZijlstra, I could not cleanly backport this to |
Sorry @JelleZijlstra, I had trouble checking out the |
Co-authored-by: Alex Waygood <[email protected]>. (cherry picked from commit 27e3665) Co-authored-by: Jelle Zijlstra <[email protected]>
GH-92270 is a backport of this pull request to the 3.10 branch. |
Co-authored-by: Alex Waygood <[email protected]>. (cherry picked from commit 27e3665) Co-authored-by: Jelle Zijlstra <[email protected]>
GH-92271 is a backport of this pull request to the 3.9 branch. |
Co-authored-by: Alex Waygood <[email protected]>. (cherry picked from commit 27e3665) Co-authored-by: Jelle Zijlstra <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>. (cherry picked from commit 27e3665) Co-authored-by: Jelle Zijlstra <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>. (cherry picked from commit 27e3665) Co-authored-by: Jelle Zijlstra <[email protected]>
I started out noticing that the link here is broken:
https://docs.python.org/3.11/library/typing.html#typing.assert_never
Then I decided to read through the whole thing and look
for other issues. I'll comment on specific things that need
explanation.
I'll backport this to 3.9 and 3.10 as much as it is applicable.