Show More
@@ -295,34 +295,59 b' class Inspector:' | |||
|
295 | 295 | |
|
296 | 296 | Optional: |
|
297 | 297 | -formatter: a function to run the docstring through for specially |
|
298 |
formatted docstrings. |
|
|
298 | formatted docstrings. | |
|
299 | ||
|
300 | Examples | |
|
301 | -------- | |
|
302 | ||
|
303 | In [1]: class NoInit: | |
|
304 | ...: pass | |
|
305 | ||
|
306 | In [2]: class NoDoc: | |
|
307 | ...: def __init__(self): | |
|
308 | ...: pass | |
|
309 | ||
|
310 | In [3]: %pdoc NoDoc | |
|
311 | No documentation found for NoDoc | |
|
312 | ||
|
313 | In [4]: %pdoc NoInit | |
|
314 | No documentation found for NoInit | |
|
315 | ||
|
316 | In [5]: obj = NoInit() | |
|
317 | ||
|
318 | In [6]: %pdoc obj | |
|
319 | No documentation found for obj | |
|
320 | ||
|
321 | In [5]: obj2 = NoDoc() | |
|
322 | ||
|
323 | In [6]: %pdoc obj2 | |
|
324 | No documentation found for obj2 | |
|
325 | """ | |
|
299 | 326 | |
|
300 | 327 | head = self.__head # For convenience |
|
328 | lines = [] | |
|
301 | 329 | ds = getdoc(obj) |
|
302 | 330 | if formatter: |
|
303 | 331 | ds = formatter(ds) |
|
304 | if inspect.isclass(obj): | |
|
332 | if ds: | |
|
333 | lines.append(head("Class Docstring:")) | |
|
334 | lines.append(indent(ds)) | |
|
335 | if inspect.isclass(obj) and hasattr(obj, '__init__'): | |
|
305 | 336 | init_ds = getdoc(obj.__init__) |
|
306 | output = "\n".join([head("Class Docstring:"), | |
|
307 | indent(ds), | |
|
308 | head("Constructor Docstring:"), | |
|
309 | indent(init_ds)]) | |
|
337 | if init_ds is not None: | |
|
338 | lines.append(head("Constructor Docstring:")) | |
|
339 | lines.append(indent(init_ds)) | |
|
310 | 340 | elif (type(obj) is types.InstanceType or isinstance(obj,object)) \ |
|
311 | 341 | and hasattr(obj,'__call__'): |
|
312 | 342 | call_ds = getdoc(obj.__call__) |
|
313 | 343 | if call_ds: |
|
314 |
|
|
|
315 | indent(ds), | |
|
316 | head("Calling Docstring:"), | |
|
317 | indent(call_ds)]) | |
|
318 | else: | |
|
319 | output = ds | |
|
320 | else: | |
|
321 | output = ds | |
|
322 | if output is None: | |
|
344 | lines.append(head("Calling Docstring:")) | |
|
345 | lines.append(indent(call_ds)) | |
|
346 | ||
|
347 | if not lines: | |
|
323 | 348 | self.noinfo('documentation',oname) |
|
324 | return | |
|
325 |
page.page( |
|
|
349 | else: | |
|
350 | page.page('\n'.join(lines)) | |
|
326 | 351 | |
|
327 | 352 | def psource(self,obj,oname=''): |
|
328 | 353 | """Print the source code for an object.""" |
General Comments 0
You need to be logged in to leave comments.
Login now