-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Further improve docs for typing.Annotated
#105498
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
Conversation
typing.Annotated
typing.Annotated
@erlend-aasland, it would be great to get some non-typing-expert eyes on this, if you have the time to take a look :) |
@AlexWaygood, I'll have a look! |
|
||
For example: | ||
where ``T1``, ``T2``, etc. are :class:`TypeVars <TypeVar>`. This would be | ||
invalid: only one type should be passed to Annotated. |
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 looks misindented, as it's indented by one space less than the next paragraph.
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.
Hmm, it seems the bulleted list is inconsistent about whether there should be one or two spaces after a bullet point.
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 decided it was probably the next paragraph that had the wrong indentation -- does it look better after 2cd15fe?
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.
Looks good, one formatting nit
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.
The new text is definitely easier to read for a typing newbie like me. Thanks!
Great to hear! |
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, looks good!
Thanks @AlexWaygood for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
GH-105503 is a backport of this pull request to the 3.12 branch. |
(cherry picked from commit d213c29) Co-authored-by: Alex Waygood <[email protected]>
GH-105504 is a backport of this pull request to the 3.11 branch. |
(cherry picked from commit d213c29) Co-authored-by: Alex Waygood <[email protected]>
* Further improve docs for `typing.Annotated` (GH-105498) (cherry picked from commit d213c29) Co-authored-by: Alex Waygood <[email protected]>
Further improve docs for `typing.Annotated` (GH-105498) (cherry picked from commit d213c29) Co-authored-by: Alex Waygood <[email protected]>
A significant followup PR to #105365.
Annotated
isn't a type, you can't use it directly as a type annotation.__metadata__
attribute at runtime, rather than "annotations" or "types", which were being used before... attribute::
directive for the__metadata__
attribute. It's not being rendered correctly -- Sphinx thinks it's a module attribute rather than an attribute ofAnnotated[X, "foo"]
. Current rendering. This is because we don't mark upAnnotated
as a class in the docs. (It actually is a class at runtime, at the moment, but that's an implementation detail. I don't think we should mark it as a class in the docs.)Annotated
type cannot be made generic over aTypeVarTuple
.get_type_hints
is to strip metadata fromAnnotated
annotations, and add an example... seealso::
box.Annotated
, which was incorrect: you subscriptAnnotated
, you don't call it.📚 Documentation preview 📚: https://cpython-previews--105498.org.readthedocs.build/