MCPcopy Create free account
hub / github.com/numpy/numpy / add_newdoc

Function add_newdoc

numpy/core/function_base.py:497–551  ·  view source on GitHub ↗

Add documentation to an existing object, typically one defined in C The purpose is to allow easier editing of the docstrings without requiring a re-compile. This exists primarily for internal use within numpy itself. Parameters ---------- place : str The absolute n

(place, obj, doc, warn_on_python=True)

Source from the content-addressed store, hash-verified

495
496
497def add_newdoc(place, obj, doc, warn_on_python=True):
498 """
499 Add documentation to an existing object, typically one defined in C
500
501 The purpose is to allow easier editing of the docstrings without requiring
502 a re-compile. This exists primarily for internal use within numpy itself.
503
504 Parameters
505 ----------
506 place : str
507 The absolute name of the module to import from
508 obj : str
509 The name of the object to add documentation to, typically a class or
510 function name
511 doc : {str, Tuple[str, str], List[Tuple[str, str]]}
512 If a string, the documentation to apply to `obj`
513
514 If a tuple, then the first element is interpreted as an attribute of
515 `obj` and the second as the docstring to apply - ``(method, docstring)``
516
517 If a list, then each element of the list should be a tuple of length
518 two - ``[(method1, docstring1), (method2, docstring2), ...]``
519 warn_on_python : bool
520 If True, the default, emit `UserWarning` if this is used to attach
521 documentation to a pure-python object.
522
523 Notes
524 -----
525 This routine never raises an error if the docstring can't be written, but
526 will raise an error if the object being documented does not exist.
527
528 This routine cannot modify read-only docstrings, as appear
529 in new-style classes or built-in functions. Because this
530 routine never raises an error the caller must check manually
531 that the docstrings were changed.
532
533 Since this function grabs the ``char *`` from a c-level str object and puts
534 it into the ``tp_doc`` slot of the type of `obj`, it violates a number of
535 C-API best-practices, by:
536
537 - modifying a `PyTypeObject` after calling `PyType_Ready`
538 - calling `Py_INCREF` on the str and losing the reference, so the str
539 will never be released
540
541 If possible it should be avoided.
542 """
543 new = getattr(__import__(place, globals(), {}, [obj]), obj)
544 if isinstance(doc, str):
545 _add_docstring(new, doc.strip(), warn_on_python)
546 elif isinstance(doc, tuple):
547 attr, docstring = doc
548 _add_docstring(getattr(new, attr), docstring.strip(), warn_on_python)
549 elif isinstance(doc, list):
550 for attr, docstring in doc:
551 _add_docstring(getattr(new, attr), docstring.strip(), warn_on_python)

Callers 3

_add_newdocs.pyFile · 0.90

Calls 2

_add_docstringFunction · 0.85
stripMethod · 0.80

Tested by

no test coverage detected