Introduce SupportsContainsAndGetItem (#11827)

This commit is contained in:
Sebastian Rittau
2024-04-24 16:19:12 +02:00
committed by GitHub
parent d0f2be92ab
commit f646eb86e2
4 changed files with 17 additions and 14 deletions

View File

@@ -18,7 +18,7 @@ class Point:
def measurement(measurement: str) -> Point: ...
@staticmethod
def from_dict(
dictionary: SupportsGetItem[str, Any],
dictionary: SupportsGetItem[str, Any], # TODO: Use SupportsContainsAndGetItem
write_precision: _WritePrecision = "ns",
*,
record_measurement_name: str | None = ...,

View File

@@ -2,23 +2,17 @@ import builtins
import operator
import types
import unittest
from _typeshed import IdentityFunction, Unused, _KT_contra, _VT_co
from _typeshed import IdentityFunction, SupportsGetItem, Unused
from builtins import next as next
from collections.abc import Callable, ItemsView, Iterable, Iterator as _Iterator, KeysView, Mapping, ValuesView
from functools import wraps as wraps
from importlib.util import spec_from_loader as spec_from_loader
from io import BytesIO as BytesIO, StringIO as StringIO
from re import Pattern
from typing import Any, AnyStr, Literal, NoReturn, Protocol, TypeVar, overload
from typing import Any, AnyStr, Literal, NoReturn, TypeVar, overload
from six import moves as moves
# TODO: We should switch to the _typeshed version of SupportsGetItem
# once mypy updates its vendored copy of typeshed and makes a new release
class _SupportsGetItem(Protocol[_KT_contra, _VT_co]):
def __contains__(self, x: Any, /) -> bool: ...
def __getitem__(self, key: _KT_contra, /) -> _VT_co: ...
_T = TypeVar("_T")
_K = TypeVar("_K")
_V = TypeVar("_V")
@@ -68,7 +62,7 @@ unichr = chr
def int2byte(i: int) -> bytes: ...
# Should be `byte2int: operator.itemgetter[int]`. But a bug in mypy prevents using TypeVar in itemgetter.__call__
def byte2int(obj: _SupportsGetItem[int, _T]) -> _T: ...
def byte2int(obj: SupportsGetItem[int, _T]) -> _T: ...
indexbytes = operator.getitem
iterbytes = iter