-
Notifications
You must be signed in to change notification settings - Fork 234
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
Import the generics documentation from mypy #1416
Conversation
reveal_type(box.first([1, 2, 3])) # Revealed type is "builtins.int" | ||
reveal_type(box.pair_with_first([1, 2, 3])) # Revealed type is "tuple[builtins.int, builtins.str]" | ||
|
||
In particular, the ``self`` argument may also be generic, allowing a |
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 example isn't great as it should be using Self
. Not sure if there's a better example to give, though.
Generics | ||
======== | ||
|
||
You may have seen type hints like ``list[str]`` or ``dict[str, int]`` in Python |
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.
General question: I'm not sure how backwards-compatible these docs are meant to be. In your last PR, I noticed you used Optional[X]
instead of X | None
throughout, but didn't mention it because I assumed you were trying to keep the code examples compatible with py38+. But this document uses PEP-585 syntax throughout, and doesn't mention the older way of writing these types until the last section right at the bottom.
I prefer making the new syntax more prominent than the old syntax, as this document does, but maybe we should have the note about how to do things in a pre-PEP-585 world slightly higher up?
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 think the ideal would be if we had some selector at the top of examples, similar to the one for Unix/Windows at https://packaging.python.org/en/latest/tutorials/packaging-projects/, where users could toggle between "Python 3.9+" and "Python 3.7-3.8" or so.
Setting that up is better left for a separate PR though.
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.
Yes, that would be ideal! And fine to leave it to another PR, agreed.
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.
For the mypy docs this is based on, I went by https://pypistats.org/packages/mypy minor version counts to determine what version should be emphasised. 3.9 is mode and median.
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Thank you everyone for reviews! |
No description provided.