Skip to content

Commit

Permalink
Simplify code in core/oinspect.py
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Jun 21, 2011
1 parent f8e5b4a commit e78a807
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions IPython/core/oinspect.py
Expand Up @@ -28,7 +28,6 @@

# IPython's own
from IPython.core import page
from IPython.external.Itpl import itpl
from IPython.utils import PyColorize
from IPython.utils import io
from IPython.utils.text import indent
Expand Down Expand Up @@ -298,22 +297,24 @@ def pdoc(self,obj,oname='',formatter = None):
-formatter: a function to run the docstring through for specially
formatted docstrings."""

head = self.__head # so that itpl can find it even if private
head = self.__head # For convenience
ds = getdoc(obj)
if formatter:
ds = formatter(ds)
if inspect.isclass(obj):
init_ds = getdoc(obj.__init__)
output = itpl('$head("Class Docstring:")\n'
'$indent(ds)\n'
'$head("Constructor Docstring"):\n'
'$indent(init_ds)')
output = "\n".join([head("Class Docstring:"),
indent(ds),
head("Constructor Docstring:"),
indent(init_ds)])
elif (type(obj) is types.InstanceType or isinstance(obj,object)) \
and hasattr(obj,'__call__'):
call_ds = getdoc(obj.__call__)
if call_ds:
output = itpl('$head("Class Docstring:")\n$indent(ds)\n'
'$head("Calling Docstring:")\n$indent(call_ds)')
output = "\n".join([head("Class Docstring:"),
indent(ds),
head("Calling Docstring:"),
indent(call_ds)])
else:
output = ds
else:
Expand Down

0 comments on commit e78a807

Please sign in to comment.