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

Update int.from_bytes to allow Iterable[int] #3571

Merged
merged 1 commit into from
Jan 5, 2020

Conversation

armooo
Copy link
Contributor

@armooo armooo commented Jan 4, 2020

Running int.from_bytes(iter([1, 0]), 'little')) returns 1 as
expected.

Copy link
Contributor

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument actually accepts more things, like SupportsBytes and buffer-protocol types (as the TODO says). I'm not sure how typeshed handles the C buffer protocol, but at least SupportsBytes can be added.

But this is already an improvement so LGTM either way.

`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.
Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@srittau srittau merged commit a1331ac into python:master Jan 5, 2020
@JelleZijlstra
Copy link
Member

python/typing#593 is the relevant issue for the buffer protocol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants