Skip to content

Commit 1a23f64

Browse files
committed
Avoid inheritance and explicitly define protocol methods
1 parent 1840a0a commit 1a23f64

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

stdlib/_typeshed/__init__.pyi

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# See the README.md file in this directory for more information.
44

55
import sys
6-
from collections.abc import Awaitable, Callable, Iterable, Sequence, Set as AbstractSet, Sized
6+
from collections.abc import Awaitable, Callable, Iterable, Iterator, Sequence, Set as AbstractSet, Sized
77
from dataclasses import Field
88
from os import PathLike
99
from types import FrameType, TracebackType
@@ -275,6 +275,16 @@ class SupportsWrite(Protocol[_T_contra]):
275275
class SupportsFlush(Protocol):
276276
def flush(self) -> object: ...
277277

278+
# Suitable for dictionary view objects
279+
class Viewable(Protocol[_T_co]):
280+
def __len__(self) -> int: ...
281+
def __iter__(self) -> Iterator[_T_co]: ...
282+
283+
class SupportsGetItemViewable(Protocol[_KT, _VT_co]):
284+
def __len__(self) -> int: ...
285+
def __iter__(self) -> Iterator[_KT]: ...
286+
def __getitem__(self, key: _KT, /) -> _VT_co: ...
287+
278288
# Unfortunately PEP 688 does not allow us to distinguish read-only
279289
# from writable buffers. We use these aliases for readability for now.
280290
# Perhaps a future extension of the buffer protocol will allow us to
@@ -377,7 +387,3 @@ if sys.version_info >= (3, 14):
377387
# These return annotations, which can be arbitrary objects
378388
AnnotateFunc: TypeAlias = Callable[[Format], dict[str, AnnotationForm]]
379389
EvaluateFunc: TypeAlias = Callable[[Format], AnnotationForm]
380-
381-
# Suitable for dictionary view objects
382-
class Viewable(Sized, Iterable[_KT_co], Protocol): ...
383-
class SupportsGetItemViewable(Viewable[_KT], SupportsGetItem[_KT, _VT_co], Protocol): ...

0 commit comments

Comments
 (0)