Raymond Hettinger <[email protected]> added the comment:
These should be left as they are because they indicate different problems and
solutions.
The Overflow errors are dependent on PY_SSIZE_T_MAX. They indicate the that
size is to big to store in a variable. Changing from a 32-bit build to a
64-bit build can alleviate this problem even on a system with the same amount
of memory.
The MemoryErrors are dependent on the size of memory. They indicate that a
malloc() or realloc() failed. This problem can be solved by adding memory.
FWIW, this isn't just limited to sequence types. Throughout the
implementation, failed memory allocations raise a MemoryError and know variable
size overflows raise an OverflowError (for example, int and float objects).
It would have been nice if the original exception hierarchy had a CapacityError
that covered both MemoryError and OverflowError. But that ship sailed long ago
and doesn't seem to have caused problems in practice.
----------------------------------
Examples:
>>> bytes(1 << 62)
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
bytes(1 << 62)
MemoryError
>>> bytes(1 << 65)
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
bytes(1 << 65)
OverflowError: cannot fit 'int' into an index-sized integer
>>> bytearray(1 << 62)
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
bytearray(1 << 62)
MemoryError
>>> bytearray(1 << 65)
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
bytearray(1 << 65)
OverflowError: cannot fit 'int' into an index-sized integer
----------
nosy: +rhettinger
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue45044>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com