Skip to content

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.


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
hswong3i pushed a commit to alvistack/python-typeshed that referenced this pull request May 25, 2025
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.

3 participants