Serhiy Storchaka added the comment:

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.

----------
nosy: +haypo

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29841>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to