-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 Generics docs page #14587
Improve Generics docs page #14587
Conversation
s = 'some string' | ||
Box[int](s) # Type error | ||
|
||
Generic class internals |
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 is moved to the bottom, since it's not the most immediately useful
@@ -478,6 +438,45 @@ type variables defined with special keyword arguments ``covariant`` or | |||
my_box = Box(Cat()) | |||
look_into(my_box) # OK, but mypy would complain here for an invariant type | |||
|
|||
.. _type-variable-upper-bound: |
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 move upper bounded type vars before value restricted type vars because they're more useful and easier to understand
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, some nitpicks around imports.
@@ -806,20 +804,18 @@ variable is invariant: | |||
|
|||
.. code-block:: python | |||
|
|||
from typing import TypeVar | |||
from typing_extensions import Protocol | |||
from typing import Protocol, TypeVar |
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 would leave this be since we still support 3.7 which doesn't have typing.Protocol.
I fixed the ParamSpec / Concatenate imports, but didn't change the Protocol one back as per my comment in #14584 (comment) (Lol, I think mypy will also happily type check this example even on 3.7 because of how magical Protocol is) |
Linking #13681