Skip to content

Commit 44da1a2

Browse files
committed
Apply review comments
1 parent 3eafa3f commit 44da1a2

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
* UFuncs new support `__dict__` attribute and allow overriding
2-
`__doc__` (either directly or via `ufunc.__dict__["__doc__"]`).
1+
* UFuncs now support `__dict__` attribute and allow overriding `__doc__`
2+
(either directly or via `ufunc.__dict__["__doc__"]`). `__dict__` can be
3+
used to also override other properties, such as `__module__` or `__qualname__`.

numpy/_core/src/umath/ufunc_object.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6448,12 +6448,7 @@ static int
64486448
ufunc_set_doc(PyUFuncObject *ufunc, PyObject *doc, void *NPY_UNUSED(ignored))
64496449
{
64506450
if (doc == NULL) {
6451-
int result = PyDict_Contains(ufunc->dict, npy_interned_str.__doc__);
6452-
if (result == 1) {
6453-
return PyDict_DelItem(ufunc->dict, npy_interned_str.__doc__);
6454-
} else {
6455-
return result;
6456-
}
6451+
return PyDict_DelItem(ufunc->dict, npy_interned_str.__doc__);
64576452
} else {
64586453
return PyDict_SetItem(ufunc->dict, npy_interned_str.__doc__, doc);
64596454
}

numpy/_core/tests/test_umath.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4034,6 +4034,8 @@ def test_ufunc_docstring(self):
40344034

40354035
del np.add.__dict__["__doc__"]
40364036
assert np.add.__doc__ == original_doc
4037+
del np.add.__dict__["other"]
4038+
assert np.add.__dict__ == {}
40374039

40384040

40394041
class TestChoose:

0 commit comments

Comments
 (0)