This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Change bytes exception when overflow
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: python-dev, serhiy.storchaka, xiang.zhang
Priority: normal Keywords: patch

Created on 2016-07-06 10:38 by xiang.zhang, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bytes_exception_msg.patch xiang.zhang, 2016-07-06 16:51 review
Messages (6)
msg269879 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-07-06 10:38
I suggest change `bytes` exception message when an iterable containing overflow integers.

Right now, bytes([sys.maxsize+1]) emits ValueError: cannot fit 'int' into an index-sized integer "ValueError: cannot fit 'int' into an index-sized integer". I think actually when use bytes in such a situation we don't care the integer overflows or not, we only care if the integer is in range(0, 256) or not, just like what bytearray([sys.maxsize+1]) does.
msg269889 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-07-06 17:21
LGTM. Are there any tests for these cases?
msg269891 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-07-06 17:31
The constructor has been well tested in https://hg.python.org/cpython/file/tip/Lib/test/test_bytes.py#l111. It looks like that the original author only wants to guarantee the exception type but not message. So I didn't add a assertRaisesRegex test.
msg269894 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-07-06 18:32
This is enough.
msg269895 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-07-06 18:40
New changeset f9481e5f1792 by Serhiy Storchaka in branch 'default':
Issue #27460: Unified error messages in bytes constructor for integers
https://hg.python.org/cpython/rev/f9481e5f1792
msg269896 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-07-06 18:41
Thank you for your contribution Xiang Zhang.
History
Date User Action Args
2022-04-11 14:58:33adminsetgithub: 71647
2016-07-06 18:41:36serhiy.storchakasetstatus: open -> closed
messages: + msg269896

components: + Interpreter Core
resolution: fixed
stage: commit review -> resolved
2016-07-06 18:40:18python-devsetnosy: + python-dev
messages: + msg269895
2016-07-06 18:32:17serhiy.storchakasetmessages: + msg269894
stage: commit review
2016-07-06 17:31:25xiang.zhangsetmessages: + msg269891
2016-07-06 17:21:50serhiy.storchakasetassignee: serhiy.storchaka

messages: + msg269889
nosy: + serhiy.storchaka
2016-07-06 16:51:24xiang.zhangsetfiles: + bytes_exception_msg.patch
2016-07-06 16:51:16xiang.zhangsetfiles: - bytes_exception_msg.patch
2016-07-06 10:39:27xiang.zhangsettype: enhancement
versions: + Python 3.6
2016-07-06 10:38:48xiang.zhangcreate