Skip to content

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

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.

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