8000 ENH: Add a `__dict__` to ufunc objects and allow overriding `__doc__` by mtsokol · Pull Request #27735 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Add a __dict__ to ufunc objects and allow overriding __doc__ #27735

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

Merged
merged 7 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply review comments
  • Loading branch information
mtsokol committed Nov 12, 2024
commit 44da1a234650837fdd64969e260bfffd88ccd075
5 changes: 3 additions & 2 deletions doc/release/upcoming_changes/27735.new_feature.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
* UFuncs new support `__dict__` attribute and allow overriding
`__doc__` (either directly or via `ufunc.__dict__["__doc__"]`).
* UFuncs now support `__dict__` attribute and allow overriding `__doc__`
(either directly or via `ufunc.__dict__["__doc__"]`). `__dict__` can be
used to also override other properties, such as `__module__` or `__qualname__`.
7 changes: 1 addition & 6 deletions numpy/_core/src/umath/ufunc_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -6448,12 +6448,7 @@ static int
ufunc_set_doc(PyUFuncObject *ufunc, PyObject *doc, void *NPY_UNUSED(ignored))
{
if (doc == NULL) {
int result = PyDict_Contains(ufunc->dict, npy_interned_str.__doc__);
if (result == 1) {
return PyDict_DelItem(ufunc->dict, npy_interned_str.__doc__);
} else {
return result;
}
return PyDict_DelItem(ufunc->dict, npy_interned_str.__doc__);
} else {
return PyDict_SetItem(ufunc->dict, npy_interned_str.__doc__, doc);
}
Expand Down
2 changes: 2 additions & 0 deletions 8587 numpy/_core/tests/test_umath.py
Original file line number Diff line number Diff line change
Expand Up @@ -4034,6 +4034,8 @@ def test_ufunc_docstring(self):

del np.add.__dict__["__doc__"]
assert np.add.__doc__ == original_doc
del np.add.__dict__["other"]
assert np.add.__dict__ == {}


class TestChoose:
Expand Down
Loading
0