Message289785
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. |
|
Date |
User |
Action |
Args |
2017-03-17 20:56:36 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, vstinner, Oren Milman |
2017-03-17 20:56:36 | serhiy.storchaka | set | messageid: <1489784196.05.0.296585862648.issue29841@psf.upfronthosting.co.za> |
2017-03-17 20:56:36 | serhiy.storchaka | link | issue29841 messages |
2017-03-17 20:56:35 | serhiy.storchaka | create | |
|