summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorda-woods <dw-git@d-woods.co.uk>2022-05-16 12:15:31 +0100
committerGitHub <noreply@github.com>2022-05-16 13:15:31 +0200
commit5cd417c3613519dd295707460ba3be4ac92e6c4d (patch)
treef099b3a8ad1248f0206ab76e6e409489b8cbcdbd
parent28857fd661946646364616073008d8e5a80ab622 (diff)
downloadcython-5cd417c3613519dd295707460ba3be4ac92e6c4d.tar.gz
Change IndexError to TypeError when calling unbound CyFunctions (GH-4783)
-rw-r--r--Cython/Utility/CythonFunction.c3
-rw-r--r--tests/run/cyfunction.pyx6
2 files changed, 9 insertions, 0 deletions
diff --git a/Cython/Utility/CythonFunction.c b/Cython/Utility/CythonFunction.c
index 5ea48ea94..b2c67dcce 100644
--- a/Cython/Utility/CythonFunction.c
+++ b/Cython/Utility/CythonFunction.c
@@ -660,6 +660,9 @@ static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, P
self = PyTuple_GetItem(args, 0);
if (unlikely(!self)) {
Py_DECREF(new_args);
+ PyErr_Format(PyExc_TypeError,
+ "unbound method %.200S() needs an argument",
+ cyfunc->func_qualname);
return NULL;
}
diff --git a/tests/run/cyfunction.pyx b/tests/run/cyfunction.pyx
index 3811b2694..f61dddb53 100644
--- a/tests/run/cyfunction.pyx
+++ b/tests/run/cyfunction.pyx
@@ -363,6 +363,9 @@ cdef class TestUnboundMethodCdef:
>>> C = TestUnboundMethodCdef
>>> IS_PY2 or (C.meth is C.__dict__["meth"])
True
+ >>> TestUnboundMethodCdef.meth() # doctest:+ELLIPSIS
+ Traceback (most recent call last):
+ TypeError: ...
"""
def meth(self): pass
@@ -372,6 +375,9 @@ class TestUnboundMethod:
>>> C = TestUnboundMethod
>>> IS_PY2 or (C.meth is C.__dict__["meth"])
True
+ >>> TestUnboundMethod.meth() # doctest:+ELLIPSIS
+ Traceback (most recent call last):
+ TypeError: ...
"""
def meth(self): pass