MCPcopy Index your code
hub / github.com/ipython/ipython / pdoc

Method pdoc

IPython/core/oinspect.py:483–537  ·  view source on GitHub ↗

Print the docstring for any object. Optional: -formatter: a function to run the docstring through for specially formatted docstrings. Examples -------- In [1]: class NoInit: ...: pass In [2]: class NoDoc: ...: d

(self, obj, oname='', formatter=None)

Source from the content-addressed store, hash-verified

481 # In Python 3, all classes are new-style, so they all have __init__.
482 @skip_doctest
483 def pdoc(self, obj, oname='', formatter=None):
484 """Print the docstring for any object.
485
486 Optional:
487 -formatter: a function to run the docstring through for specially
488 formatted docstrings.
489
490 Examples
491 --------
492 In [1]: class NoInit:
493 ...: pass
494
495 In [2]: class NoDoc:
496 ...: def __init__(self):
497 ...: pass
498
499 In [3]: %pdoc NoDoc
500 No documentation found for NoDoc
501
502 In [4]: %pdoc NoInit
503 No documentation found for NoInit
504
505 In [5]: obj = NoInit()
506
507 In [6]: %pdoc obj
508 No documentation found for obj
509
510 In [5]: obj2 = NoDoc()
511
512 In [6]: %pdoc obj2
513 No documentation found for obj2
514 """
515
516 lines = []
517 ds = getdoc(obj)
518 if formatter:
519 ds = formatter(ds).get('plain/text', ds)
520 if ds:
521 lines.append(self.__head("Class docstring:"))
522 lines.append(indent(ds))
523 if inspect.isclass(obj) and hasattr(obj, '__init__'):
524 init_ds = getdoc(obj.__init__)
525 if init_ds is not None:
526 lines.append(self.__head("Init docstring:"))
527 lines.append(indent(init_ds))
528 elif hasattr(obj,'__call__'):
529 call_ds = getdoc(obj.__call__)
530 if call_ds:
531 lines.append(self.__head("Call docstring:"))
532 lines.append(indent(call_ds))
533
534 if not lines:
535 self.noinfo('documentation',oname)
536 else:
537 page.page('\n'.join(lines))
538
539 def psource(self, obj, oname=''):
540 """Print the source code for an object."""

Callers

nothing calls this directly

Calls 6

__headMethod · 0.95
noinfoMethod · 0.95
indentFunction · 0.90
getdocFunction · 0.85
getMethod · 0.80
pageMethod · 0.80

Tested by

no test coverage detected