Skip to content

BUG,ENH: cython stubs should use except (0|-1?) etc. for integer returning functions #19291

@zoj613

Description

@zoj613

According to the docs PyArray_IntpConverter is supposed to just return NPY_FAIL (0) on failure and NPY_SUCCESS (1) otherwise. So to help manually raise an exception I write something like:

cdef np.PyArray_Dims shape
if not np.PyArray_IntpConverter(size, &shape):
	raise ValueError("`size` is not a valid argument.")

But this ends up raising a SystemError with the message: <class 'ValueError'> returned a result with an error set, Which ends up causing unittests to fail since the intended ValueError is not raised.

Reproducing code example:

Passing a set for size instead of the expected tuple.

Is there a way to silence the SystemError and only raise the intended one?

NumPy/Python version information:

1.19.0 3.6.12 (default, May 11 2021, 17:48:34) 
[GCC 10.2.0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    00 - BugProjectPossible project, may require specific skills and long commitment

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions