[issue45044] Agreeing on error raised by large repeat value for sequences

2021-08-29 Thread Raymond Hettinger


Raymond Hettinger  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 "", line 1, in 
bytes(1 << 62)
MemoryError

>>> bytes(1 << 65)
Traceback (most recent call last):
  File "", line 1, in 
bytes(1 << 65)
OverflowError: cannot fit 'int' into an index-sized integer

>>> bytearray(1 << 62)
Traceback (most recent call last):
  File "", line 1, in 
bytearray(1 << 62)
MemoryError

>>> bytearray(1 << 65)
Traceback (most recent call last):
  File "", line 1, in 
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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45044] Agreeing on error raised by large repeat value for sequences

2021-08-29 Thread Jim Fasarakis-Hilliard


New submission from Jim Fasarakis-Hilliard :

There's currently a slight disagreement between some of the sequences about 
what is raised when the value for `repeat` is too large. 

Currently, `str` and `bytes` raise an `OverflowError` while `bytearray`, 
`tuple`, `list` and `deque` raise a `MemoryError`.

To make things more confusing, if we exercise a different path not currently 
caught by the check, both `str` and `bytes` raise `MemoryError`s:

>>> b'abc' * maxsize
Traceback (most recent call last):
  File "", line 1, in 
OverflowError: repeated bytes are too long
>>> b'a' * maxsize
Traceback (most recent call last):
  File "", line 1, in 
MemoryError

Not sure what the original rationale for having these `OverflowError`s was but, 
should we change them to `MemoryError`s?

--
messages: 400527
nosy: Jim Fasarakis-Hilliard
priority: normal
severity: normal
status: open
title: Agreeing on error raised by large repeat value for sequences
type: behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com