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? |