Update int.from_bytes to allow more than sequences (#3571)

`int.from_bytes` supports both iterables of ints and objects that define
__bytes__'.  As an example `int.from_bytes(iter([1, 0]), 'little'))`
returns 1.
This commit is contained in:
Jason
2020-01-05 07:02:10 -08:00
committed by Sebastian Rittau
parent b7530cc79e
commit a1331accbe
2 changed files with 2 additions and 2 deletions

View File

@@ -157,7 +157,7 @@ class int:
if sys.version_info >= (3,):
def to_bytes(self, length: int, byteorder: str, *, signed: bool = ...) -> bytes: ...
@classmethod
def from_bytes(cls, bytes: Sequence[int], byteorder: str, *,
def from_bytes(cls, bytes: Union[Iterable[int], SupportsBytes], byteorder: str, *,
signed: bool = ...) -> int: ... # TODO buffer object argument
def __add__(self, x: int) -> int: ...

View File

@@ -157,7 +157,7 @@ class int:
if sys.version_info >= (3,):
def to_bytes(self, length: int, byteorder: str, *, signed: bool = ...) -> bytes: ...
@classmethod
def from_bytes(cls, bytes: Sequence[int], byteorder: str, *,
def from_bytes(cls, bytes: Union[Iterable[int], SupportsBytes], byteorder: str, *,
signed: bool = ...) -> int: ... # TODO buffer object argument
def __add__(self, x: int) -> int: ...