Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make Mapping covariant. #512

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

Merged
merged 3 commits into from
Sep 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions stdlib/2.7/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,21 @@ class ValuesView(MappingView, Iterable[_VT_co], Generic[_VT_co]):
def __contains__(self, o: object) -> bool: ...
def __iter__(self) -> Iterator[_VT_co]: ...

class Mapping(Sized, Iterable[_KT], Container[_KT], Generic[_KT, _VT]):
class Mapping(Sized, Iterable[_KT], Container[_KT], Generic[_KT, _VT_co]):
# TODO: We wish the key type could also be covariant, but that doesn't work,
# see discussion in https://github.com/python/typing/pull/273.
@abstractmethod
def __getitem__(self, k: _KT) -> _VT: ...
def __getitem__(self, k: _KT) -> _VT_co:
...
# Mixin methods
def get(self, k: _KT, default: _VT = ...) -> _VT: ...
def get(self, k: _KT, default: _VT_co = ...) -> _VT_co: # type: ignore
...
def keys(self) -> list[_KT]: ...
def values(self) -> list[_VT]: ...
def items(self) -> list[Tuple[_KT, _VT]]: ...
def values(self) -> list[_VT_co]: ...
def items(self) -> list[Tuple[_KT, _VT_co]]: ...
def iterkeys(self) -> Iterator[_KT]: ...
def itervalues(self) -> Iterator[_VT]: ...
def iteritems(self) -> Iterator[Tuple[_KT, _VT]]: ...
def itervalues(self) -> Iterator[_VT_co]: ...
def iteritems(self) -> Iterator[Tuple[_KT, _VT_co]]: ...
def __contains__(self, o: object) -> bool: ...

class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT]):
Expand Down
16 changes: 9 additions & 7 deletions stdlib/3/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
# TODO: Value type should be covariant, but currently we can't give a good signature for
# get if this is the case.
class Mapping(Iterable[_KT], Container[_KT], Sized, Generic[_KT, _VT_co]):
# TODO: We wish the key type could also be covariant, but that doesn't work,
# see discussion in https://github.com/python/typing/pull/273.
@abstractmethod
def __getitem__(self, k: _KT) -> _VT: ...
def __getitem__(self, k: _KT) -> _VT_co:
...
# Mixin methods
def get(self, k: _KT, default: _VT = ...) -> _VT: ...
def items(self) -> AbstractSet[Tuple[_KT, _VT]]: ...
def get(self, k: _KT, default: _VT_co = ...) -> _VT_co: # type: ignore
...
def items(self) -> AbstractSet[Tuple[_KT, _VT_co]]: ...
def keys(self) -> AbstractSet[_KT]: ...
def values(self) -> ValuesView[_VT]: ...
def values(self) -> ValuesView[_VT_co]: ...
def __contains__(self, o: object) -> bool: ...

class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT]):
Expand Down