Author Oren Milman
Recipients Oren Milman, serhiy.storchaka
Date 2017-03-17.20:33:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1489782795.95.0.350894370649.issue29841@psf.upfronthosting.co.za>
In-reply-to
Content
currently (on my Windows 10):
>>> bytes(-1 << 1000)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: cannot fit 'int' into an index-sized integer
>>> bytes(-1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: negative count
>>> bytes(sys.maxsize + 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: cannot fit 'int' into an index-sized integer

for the same size arguments, bytearray raises the same errors.

thus, in accordance with #29833 (this is a sub-issue of #29833) for each of the
constructors of bytes and bytearray:
    1. ValueErrors with the same error message should be raised for any
       negative size argument (big negative as well as small negative).
    2. MemoryError should be raised for any size argument bigger than
       sys.maxsize.


Moreover, currently:
>>> bytes(sys.maxsize - 25)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
MemoryError
>>> bytes(sys.maxsize - 24)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: byte string is too large
>>> bytes(sys.maxsize)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: byte string is too large

for each of these size arguments, bytearray raises a MemoryError.

IMHO, to make the error messages more consistent, the constructor of bytes
should raise a MemoryError for any too large size argument, as the constructor
of bytearray already does.
History
Date User Action Args
2017-03-17 20:33:15Oren Milmansetrecipients: + Oren Milman, serhiy.storchaka
2017-03-17 20:33:15Oren Milmansetmessageid: <1489782795.95.0.350894370649.issue29841@psf.upfronthosting.co.za>
2017-03-17 20:33:15Oren Milmanlinkissue29841 messages
2017-03-17 20:33:15Oren Milmancreate