Skip to content

KeysView's internal mapping no longer expresses __contains__ #14884

@iutlu

Description

@iutlu

With this PR #14574, the previous Mapping annotation for the internal mapping attribute of KeysView seems to have been changed to a Viewable protocol:

# Suitable for dictionary view objects
class Viewable(Protocol[_T_co]):
    def __len__(self) -> int: ...
    def __iter__(self) -> Iterator[_T_co]: ...

I was comparing this against CPython's collections.abc

class KeysView(MappingView, Set):

    __slots__ = ()

    @classmethod
    def _from_iterable(cls, it):
        return set(it)

    def __contains__(self, key):
        return key in self._mapping

    def __iter__(self):
        yield from self._mapping

and it appears that self._mapping has now lost the __contains__ (which was previously guaranteed by Mapping). Wanted to raise it here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions