-
-
Notifications
You must be signed in to change notification settings - Fork 32k
bytes.fromhex() should parse a bytes #129349
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
Comments
You have to look at the discussion that preceded introduction of BTW, |
For reference, |
Co-authored-by: Bénédikt Tran <[email protected]> Co-authored-by: Victor Stinner <[email protected]>
Implemented in e0637ce. |
I had doubts about supporting the general buffer protocol (see #779 and #71759). The buffer protocol is for binary data, and here we have text data. But it is difficult to decide in which cases to support only Note also that the |
IMO it's convenient to accept bytes when the "text" is ASCII only. |
…ython#129844) Co-authored-by: Bénédikt Tran <[email protected]> Co-authored-by: Victor Stinner <[email protected]>
Feature or enhancement
Proposal:
bytes.fromhex()
should accept abytes
:Background:
bytes.fromhex()
accepts astr
:However, it refuses to parse a byte string:
This requires an extra
.decode()
, which is rather wasteful given that thestr
is not of any real use.This came up for me in parsing the output of
git cat-file --batch
, which must be a binary stream because it contains bytes, but includes header lines likeThe integers are parseable directly from bytes:
so it seems like an omission that the SHAs are not.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: