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

Improve Generics docs page #14587

Merged
merged 4 commits into from
Feb 2, 2023
Merged

Improve Generics docs page #14587

merged 4 commits into from
Feb 2, 2023

Conversation

hauntsaninja
Copy link
Collaborator

Linking #13681

s = 'some string'
Box[int](s) # Type error

Generic class internals
Copy link
Collaborator Author

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:
Copy link
Collaborator Author

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

Copy link
Member

@JelleZijlstra JelleZijlstra left a 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.

docs/source/generics.rst Outdated Show resolved Hide resolved
@@ -806,20 +804,18 @@ variable is invariant:

.. code-block:: python

from typing import TypeVar
from typing_extensions import Protocol
from typing import Protocol, TypeVar
Copy link
Member

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.

@hauntsaninja
Copy link
Collaborator Author

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)

@hauntsaninja hauntsaninja merged commit e2e0fbe into python:master Feb 2, 2023
@hauntsaninja hauntsaninja deleted the docs6 branch February 2, 2023 20:43
hauntsaninja added a commit that referenced this pull request Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants