Show More
@@ -295,34 +295,59 b' class Inspector:' | |||||
295 |
|
295 | |||
296 | Optional: |
|
296 | Optional: | |
297 | -formatter: a function to run the docstring through for specially |
|
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 | head = self.__head # For convenience |
|
327 | head = self.__head # For convenience | |
|
328 | lines = [] | |||
301 | ds = getdoc(obj) |
|
329 | ds = getdoc(obj) | |
302 | if formatter: |
|
330 | if formatter: | |
303 | ds = formatter(ds) |
|
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 | init_ds = getdoc(obj.__init__) |
|
336 | init_ds = getdoc(obj.__init__) | |
306 | output = "\n".join([head("Class Docstring:"), |
|
337 | if init_ds is not None: | |
307 | indent(ds), |
|
338 | lines.append(head("Constructor Docstring:")) | |
308 | head("Constructor Docstring:"), |
|
339 | lines.append(indent(init_ds)) | |
309 | indent(init_ds)]) |
|
|||
310 | elif (type(obj) is types.InstanceType or isinstance(obj,object)) \ |
|
340 | elif (type(obj) is types.InstanceType or isinstance(obj,object)) \ | |
311 | and hasattr(obj,'__call__'): |
|
341 | and hasattr(obj,'__call__'): | |
312 | call_ds = getdoc(obj.__call__) |
|
342 | call_ds = getdoc(obj.__call__) | |
313 | if call_ds: |
|
343 | if call_ds: | |
314 |
|
|
344 | lines.append(head("Calling Docstring:")) | |
315 | indent(ds), |
|
345 | lines.append(indent(call_ds)) | |
316 | head("Calling Docstring:"), |
|
346 | ||
317 | indent(call_ds)]) |
|
347 | if not lines: | |
318 | else: |
|
|||
319 | output = ds |
|
|||
320 | else: |
|
|||
321 | output = ds |
|
|||
322 | if output is None: |
|
|||
323 | self.noinfo('documentation',oname) |
|
348 | self.noinfo('documentation',oname) | |
324 | return |
|
349 | else: | |
325 |
page.page( |
|
350 | page.page('\n'.join(lines)) | |
326 |
|
351 | |||
327 | def psource(self,obj,oname=''): |
|
352 | def psource(self,obj,oname=''): | |
328 | """Print the source code for an object.""" |
|
353 | """Print the source code for an object.""" |
General Comments 0
You need to be logged in to leave comments.
Login now