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

How about making an immutabledict class where the value is covariant? #243

Closed
spacether opened this issue Jul 19, 2023 · 2 comments
Closed

Comments

@spacether
Copy link
Contributor

spacether commented Jul 19, 2023

How about making an immutabledict class where the value is covariant?
Other immutable containers are all covariant (Union, Tuple Sequence etc).
Because the _K is by default not covariant, my type hints did not work when they should have.
This was uncovered here: python/mypy#15710

Note: the copy method must be removed if you do that per pylance or mypy

@sterliakov
Copy link

To add on this, you won't have to remove the copy method. It could be

def copy(self, **add_or_replace: _U) -> immutabledict[_K, _V | _U]: ...

to resolve variance issues (with add_or_replace: _V _V cannot be covariant), where _U is another unbound type variable. Since your mapping is immutable, why constraint users in creating another instances with different types?

@corenting
Copy link
Owner

Fixed with #244 , closing the issue

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

No branches or pull requests

3 participants