Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 45c4a8d

Browse files
mattiperic-wieser
authored andcommitted
DOC: point out the shortcomings of add_newdocs
1 parent f730ea8 commit 45c4a8d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

numpy/core/function_base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,16 @@ def add_newdoc(place, obj, doc):
467467
in new-style classes or built-in functions. Because this
468468
routine never raises an error the caller must check manually
469469
that the docstrings were changed.
470+
471+
Since this function grabs the ``char *`` from a c-level str object and puts
472+
it into the ``tp_doc`` slot of the type of `obj`, it violates a number of
473+
C-API best-practices, by:
474+
475+
- modifying a `PyTypeObject` after calling `PyType_Ready`
476+
- calling `Py_INCREF` on the str and losing the reference, so the str
477+
will never be released
478+
479+
If possible it should be avoided.
470480
"""
471481
new = getattr(__import__(place, globals(), {}, [obj]), obj)
472482
if isinstance(doc, str):

0 commit comments

Comments
 (0)