bpo-29843: Raise ValueError instead of OverflowError in case of a negative length in a ctypes.Array subclass by orenmn · Pull Request #3822 · python/cpython (original) (raw)

It is not so easy, since length is of type Py_ssize_t.

In addition, there is a behavior difference between PyLong_AsSsize_t() and PyLong_AsLongAndOverflow(). The latter accepts not just int and its subclasses, but also obbjects implementing __int__ (e.g. float). This is not desirable.