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.

Author serhiy.storchaka
Recipients Oren Milman, serhiy.storchaka, vstinner
Date 2017-03-17.20:56:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1489784196.05.0.296585862648.issue29841@psf.upfronthosting.co.za>
In-reply-to
Content
I worked on this issue. The simplest solution is calling PyNumber_AsSsize_t() with NULL rather than PyExc_OverflowError in bytes and bytearray constructors. Then both constructors will raise ValueError for large negative size and bytearray() will raise MemoryError for large positive size. For raising MemoryError in bytes() we should change OverflowError to MemoryError in other place.

But this is not the only difference between bytes and bytearray.

>>> bytearray(b'abcd') * sys.maxsize
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
MemoryError
>>> b'abcd' * sys.maxsize
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: repeated bytes are too long

This looks related and I think that it is worth to change OverflowError to MemoryError in the repetition operation. But 'abcd' * sys.maxsize raises OverflowError too, therefore we should change exception types in str.

Concatenation also can raise OverflowError. If change OverflowError to MemoryError in above operations, it should be changed for concatenation too.
History
Date User Action Args
2017-03-17 20:56:36serhiy.storchakasetrecipients: + serhiy.storchaka, vstinner, Oren Milman
2017-03-17 20:56:36serhiy.storchakasetmessageid: <1489784196.05.0.296585862648.issue29841@psf.upfronthosting.co.za>
2017-03-17 20:56:36serhiy.storchakalinkissue29841 messages
2017-03-17 20:56:35serhiy.storchakacreate