Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of byte2int with bytes #9152

Merged
merged 5 commits into from
Nov 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions stubs/six/six/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ import builtins
import operator
import types
import unittest
from _typeshed import IdentityFunction, SupportsGetItem
from _typeshed import IdentityFunction, _KT_contra, _VT_co
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, NoReturn, TypeVar, overload
from typing import Any, AnyStr, NoReturn, Protocol, TypeVar, overload
from typing_extensions import Literal

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")
Expand Down Expand Up @@ -65,8 +71,8 @@ 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: ...
# Should be `byte2int: operator.itemgetter[int]`. But a bug in mypy prevents using TypeVar in itemgetter.__call__
def byte2int(obj: _SupportsGetItem[int, _T]) -> _T: ...

indexbytes = operator.getitem
iterbytes = iter
Expand Down