@@ -2,18 +2,24 @@ import builtins
2
2
import operator
3
3
import types
4
4
import unittest
5
- from _typeshed import IdentityFunction , SupportsGetItem
5
+ from _typeshed import IdentityFunction , _KT_contra , _VT_co
6
6
from builtins import next as next
7
7
from collections .abc import Callable , ItemsView , Iterable , Iterator as _Iterator , KeysView , Mapping , ValuesView
8
8
from functools import wraps as wraps
9
9
from importlib .util import spec_from_loader as spec_from_loader
10
10
from io import BytesIO as BytesIO , StringIO as StringIO
11
11
from re import Pattern
12
- from typing import Any , AnyStr , NoReturn , TypeVar , overload
12
+ from typing import Any , AnyStr , NoReturn , Protocol , TypeVar , overload
13
13
from typing_extensions import Literal
14
14
15
15
from six import moves as moves
16
16
17
+ # TODO: We should switch to the _typeshed version of SupportsGetItem
18
+ # once mypy updates its vendored copy of typeshed and makes a new release
19
+ class _SupportsGetItem (Protocol [_KT_contra , _VT_co ]):
20
+ def __contains__ (self , __x : Any ) -> bool : ...
21
+ def __getitem__ (self , __key : _KT_contra ) -> _VT_co : ...
22
+
17
23
_T = TypeVar ("_T" )
18
24
_K = TypeVar ("_K" )
19
25
_V = TypeVar ("_V" )
@@ -65,8 +71,8 @@ unichr = chr
65
71
66
72
def int2byte (i : int ) -> bytes : ...
67
73
68
- # Should be `byte2int: operator.itemgetter[int]`. But a bug in mypy prevents using TypeVar in itemgetter__call__
69
- def byte2int (obj : SupportsGetItem [int , _T ]) -> _T : ...
74
+ # Should be `byte2int: operator.itemgetter[int]`. But a bug in mypy prevents using TypeVar in itemgetter.__call__
75
+ def byte2int (obj : _SupportsGetItem [int , _T ]) -> _T : ...
70
76
71
77
indexbytes = operator .getitem
72
78
iterbytes = iter
0 commit comments