GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge pull request #24031 from seberg/array-ufunc-no-kwargs · numpy/numpy@0e2af84

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • numpy/core
    • src/multiarray
      • methods.c
    • tests
      • test_umath.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎numpy/core/src/multiarray/methods.c‎

Copy file name to clipboardExpand all lines: numpy/core/src/multiarray/methods.c
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,9 @@ any_array_ufunc_overrides(PyObject *args, PyObject *kwds)
11351135
}
11361136
}
11371137
Py_DECREF(fast);
1138+
if (kwds == NULL) {
1139+
return 0;
1140+
}
11381141
/* check outputs, if any */
11391142
nout = PyUFuncOverride_GetOutObjects(kwds, &out_kwd_obj, &out_objs);
11401143
if (nout < 0) {
Collapse file

‎numpy/core/tests/test_umath.py‎

Copy file name to clipboardExpand all lines: numpy/core/tests/test_umath.py
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3916,6 +3916,19 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
39163916
assert_equal(a, check)
39173917
assert_(a.info, {'inputs': [0, 2]})
39183918

3919+
def test_array_ufunc_direct_call(self):
3920+
# This is mainly a regression test for gh-24023 (shouldn't segfault)
3921+
a = np.array(1)
3922+
with pytest.raises(TypeError):
3923+
a.__array_ufunc__()
3924+
3925+
# No kwargs means kwargs may be NULL on the C-level
3926+
with pytest.raises(TypeError):
3927+
a.__array_ufunc__(1, 2)
3928+
3929+
# And the same with a valid call:
3930+
res = a.__array_ufunc__(np.add, "__call__", a, a)
3931+
assert_array_equal(res, a + a)
39193932

39203933
class TestChoose:
39213934
def test_mixed(self):

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.