Skip to content

Commit 14a43b8

Browse files
authored
Fix usage of byte2int with bytes (#9152)
1 parent 17d6b97 commit 14a43b8

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

stubs/six/six/__init__.pyi

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@ import builtins
22
import operator
33
import types
44
import unittest
5-
from _typeshed import IdentityFunction, SupportsGetItem
5+
from _typeshed import IdentityFunction, _KT_contra, _VT_co
66
from builtins import next as next
77
from collections.abc import Callable, ItemsView, Iterable, Iterator as _Iterator, KeysView, Mapping, ValuesView
88
from functools import wraps as wraps
99
from importlib.util import spec_from_loader as spec_from_loader
1010
from io import BytesIO as BytesIO, StringIO as StringIO
1111
from re import Pattern
12-
from typing import Any, AnyStr, NoReturn, TypeVar, overload
12+
from typing import Any, AnyStr, NoReturn, Protocol, TypeVar, overload
1313
from typing_extensions import Literal
1414

1515
from six import moves as moves
1616

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+
1723
_T = TypeVar("_T")
1824
_K = TypeVar("_K")
1925
_V = TypeVar("_V")
@@ -65,8 +71,8 @@ unichr = chr
6571

6672
def int2byte(i: int) -> bytes: ...
6773

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: ...
7076

7177
indexbytes = operator.getitem
7278
iterbytes = iter

0 commit comments

Comments
 (0)