Skip to content

Fix issue #9296 (calling register on KeysView subclass causes false positive error) #9348

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 5 commits into from
Dec 10, 2022
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
7 changes: 5 additions & 2 deletions stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class SupportsRound(Protocol[_T_co]):
def __round__(self, __ndigits: int) -> _T_co: ...

@runtime_checkable
class Sized(Protocol):
class Sized(Protocol, metaclass=ABCMeta):
@abstractmethod
def __len__(self) -> int: ...

Expand Down Expand Up @@ -452,7 +452,10 @@ class Container(Protocol[_T_co]):
def __contains__(self, __x: object) -> bool: ...

@runtime_checkable
class Collection(Sized, Iterable[_T_co], Container[_T_co], Protocol[_T_co]): ...
class Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]):
# Implement Sized (but don't have it as a base class).
@abstractmethod
def __len__(self) -> int: ...

class Sequence(Collection[_T_co], Reversible[_T_co], Generic[_T_co]):
@overload
Expand Down
16 changes: 16 additions & 0 deletions test_cases/stdlib/typing/check_regression_issue_9296.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from __future__ import annotations

import typing as t

KT = t.TypeVar("KT")


class MyKeysView(t.KeysView[KT]):
pass


d: dict[t.Any, t.Any] = {}
dict_keys = type(d.keys())

# This should not cause an error like `Member "register" is unknown`:
MyKeysView.register(dict_keys)