[New-bugs-announce] [issue29843] errors raised by ctypes.Array for invalid _length_ attribute
Oren Milman
report at bugs.python.org
Sat Mar 18 05:56:32 EDT 2017
New submission from Oren Milman:
With regard to ctypes.Array:
currently:
>>> from ctypes import *
>>> class T(Array):
... _type_ = c_int
... _length_ = -1
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: array too large
>>> class T(Array):
... _type_ = c_int
... _length_ = -1 << 1000
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: The '_length_' attribute is too large
Obviously, here the _length_ attribute is too small, not too large.
Thus, the error messages should be changed to be more accurate (optimally, for
any negative _length_, the error message should be the same).
Moreover, in accordance with #29833 (this is a sub-issue of #29833), ValueError
should be raised for any negative _length_ attribute (instead of
OverflowError).
Also, Note that currently, in case _length_ == 0, no error is raised. ISTM that
a ctypes Array of length 0 is useless, so maybe we should raise a ValueError in
this case too?
----------
components: ctypes
messages: 289800
nosy: Oren Milman, serhiy.storchaka
priority: normal
severity: normal
status: open
title: errors raised by ctypes.Array for invalid _length_ attribute
type: behavior
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29843>
_______________________________________
More information about the New-bugs-announce
mailing list