-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
bpo-39689: Do not use native packing for format "?" with standard size #18969
bpo-39689: Do not use native packing for format "?" with standard size #18969
Conversation
This implements the current documentation somewhat pedantically:
We always have >>> from struct import *
>>> unpack("?", b"\x02")
/home/stefan/cpython/Modules/_struct.c:487:12: runtime error: load of value 2, which is not a valid value for type '_Bool'
(False,) This, however, should pass (and does after this patch): >>> unpack("<?", b"\x02")
(True,) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs currently say:
For the '?' format character, the return value is either True or False. When packing, the truth value of the argument object is used. Either 0 or 1 in the native or standard bool representation will be packed, and any non-zero value will be True when unpacking.
So, if we do want change that and expose UB to Python, the docs need to change. IMO, this will need a news entry as well.
The docs also currently talk about the characters @=<>!
only affecting byte order, size, and alignment. Will that need to be expanded?
When you're done making the requested changes, leave the comment: |
Thanks @skrah for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7. |
Thanks @skrah for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8. |
GH-19154 is a backport of this pull request to the 3.7 branch. |
GH-19155 is a backport of this pull request to the 3.8 branch. |
pythonGH-18969) (cherry picked from commit 472fc84) Co-authored-by: Stefan Krah <[email protected]>
pythonGH-18969) (cherry picked from commit 472fc84) Co-authored-by: Stefan Krah <[email protected]>
GH-18969) (cherry picked from commit 472fc84) Co-authored-by: Stefan Krah <[email protected]>
GH-18969) (cherry picked from commit 472fc84) Co-authored-by: Stefan Krah <[email protected]>
https://bugs.python.org/issue39689
Automerge-Triggered-By: @encukou