|
3 | 3 | # See the README.md file in this directory for more information. |
4 | 4 |
|
5 | 5 | 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 |
7 | 7 | from dataclasses import Field |
8 | 8 | from os import PathLike |
9 | 9 | from types import FrameType, TracebackType |
@@ -275,6 +275,16 @@ class SupportsWrite(Protocol[_T_contra]): |
275 | 275 | class SupportsFlush(Protocol): |
276 | 276 | def flush(self) -> object: ... |
277 | 277 |
|
| 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 | + |
278 | 288 | # Unfortunately PEP 688 does not allow us to distinguish read-only |
279 | 289 | # from writable buffers. We use these aliases for readability for now. |
280 | 290 | # Perhaps a future extension of the buffer protocol will allow us to |
@@ -377,7 +387,3 @@ if sys.version_info >= (3, 14): |
377 | 387 | # These return annotations, which can be arbitrary objects |
378 | 388 | AnnotateFunc: TypeAlias = Callable[[Format], dict[str, AnnotationForm]] |
379 | 389 | 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