-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-74020: Raise ValueError for negative values converted to unsigned #121114
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
ff4cfc8
1af7897
51c8b22
8701b4a
7685781
0300d31
8526ac6
d54127d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1377,8 +1377,8 @@ def equivalent_python(n, length, byteorder, signed=False): | |
self.assertRaises(OverflowError, (256).to_bytes, 1, 'big', signed=True) | ||
self.assertRaises(OverflowError, (256).to_bytes, 1, 'little', signed=False) | ||
self.assertRaises(OverflowError, (256).to_bytes, 1, 'little', signed=True) | ||
self.assertRaises(OverflowError, (-1).to_bytes, 2, 'big', signed=False) | ||
self.assertRaises(OverflowError, (-1).to_bytes, 2, 'little', signed=False) | ||
self.assertRaises(ValueError, (-1).to_bytes, 2, 'big', signed=False) | ||
self.assertRaises(ValueError, (-1).to_bytes, 2, 'little', signed=False) | ||
Comment on lines
+1380
to
+1381
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should adjust int.to_bytes() docs (both docstring and sphinx). BTW, I think there could be a test with a negative input and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated docs. There is a test with a negative input and signed=True above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hmm, maybe. I don't see it. |
||
self.assertEqual((0).to_bytes(0, 'big'), b'') | ||
self.assertEqual((1).to_bytes(5, 'big'), b'\x00\x00\x00\x00\x01') | ||
self.assertEqual((0).to_bytes(5, 'big'), b'\x00\x00\x00\x00\x00') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Converting negative Python integer to a C unsigned integer type now raises | ||
:exc:`ValueError`, not :exc:`OverflowError`. |
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.
This will need to be moved to 3.15 and marked as an incompatible change.