From a1331accbe98ae5f214b824121e5223e52a474f7 Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 5 Jan 2020 07:02:10 -0800 Subject: [PATCH] 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. --- stdlib/2/__builtin__.pyi | 2 +- stdlib/2and3/builtins.pyi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 43de5b018..1ac5397e0 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -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: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 43de5b018..1ac5397e0 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -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: ...