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

Make Mapping covariant. #512

Merged
merged 3 commits into from
Sep 5, 2016
Merged

Make Mapping covariant. #512

merged 3 commits into from
Sep 5, 2016

Conversation

gvanrossum
Copy link
Member

@gvanrossum gvanrossum commented Aug 30, 2016

Fixes #510.

This requires a # type: ignore on __getitem__ and get because
mypy complains about covariant parameters.

FWIW typing.py needs to be changed too. (It was covariant in the
value but invariant in the key -- typeshed was invariant in both.)

See also python/typing#273.

@@ -226,16 +226,18 @@ class ValuesView(MappingView, Iterable[_VT_co], Generic[_VT_co]):

# TODO: ContextManager (only if contextlib.AbstractContextManager exists)

class Mapping(Iterable[_KT], Container[_KT], Sized, Generic[_KT, _VT]):
class Mapping(Iterable[_KT_co], Container[_KT_co], Sized, Generic[_KT_co, _VT_co]):
# TODO: Value type should be covariant, but currently we can't give a good signature for
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment comment is out of date.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guido van Rossum and others added 3 commits September 2, 2016 16:14
Fixes #510.

This requires a `# type: ignore` on `__getitem__` and `get` because
mypy complains about covariant parameters.

FWIW typing.py needs to be changed too.  (It was covariant in the
value but invariant in the key -- typeshed was invariant in both.)
@gvanrossum
Copy link
Member Author

OK, as a compromise I am making it covariant in the value only. (It was already that way in typing.py.) There's still a # type: ignore on the definition of get(), mypy doesn't believe the hack @JukkaL suggested yet.

@JukkaL JukkaL merged commit 25cb6e4 into master Sep 5, 2016
@gvanrossum gvanrossum deleted the covariant-mapping branch October 19, 2016 22:30
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