Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Avoid intp conversion regression in Cython 3 (backport) #25095

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion numpy/__init__.cython-30.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cdef extern from *:


cdef extern from "Python.h":
ctypedef Py_ssize_t Py_intptr_t
ctypedef int Py_intptr_t

cdef extern from "numpy/arrayobject.h":
ctypedef Py_intptr_t npy_intp
Expand Down
3 changes: 3 additions & 0 deletions numpy/core/tests/examples/cython/checks.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ def get_dt64_unit(obj):

def is_integer(obj):
return isinstance(obj, (cnp.integer, int))

def conv_intp(cnp.intp_t val):
return val
11 changes: 11 additions & 0 deletions numpy/core/tests/test_cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,14 @@ def test_abstract_scalars(install_temp):
assert checks.is_integer(1)
assert checks.is_integer(np.int8(1))
assert checks.is_integer(np.uint64(1))

def test_conv_intp(install_temp):
import checks

class myint:
def __int__(self):
return 3

# These conversion passes via `__int__`, not `__index__`:
assert checks.conv_intp(3.) == 3
assert checks.conv_intp(myint()) == 3