Commit 9be283a7 authored by Ka-Ping Yee's avatar Ka-Ping Yee

Handle old-style instances more gracefully (display documentation on

the relevant class instead of documentation on <type 'instance'>).
parent 681cb325
...@@ -1448,6 +1448,9 @@ def locate(path, forceload=0): ...@@ -1448,6 +1448,9 @@ def locate(path, forceload=0):
text = TextDoc() text = TextDoc()
html = HTMLDoc() html = HTMLDoc()
class _OldStyleClass: pass
_OLD_INSTANCE_TYPE = type(_OldStyleClass())
def resolve(thing, forceload=0): def resolve(thing, forceload=0):
"""Given an object or a path to an object, get the object and its name.""" """Given an object or a path to an object, get the object and its name."""
if isinstance(thing, str): if isinstance(thing, str):
...@@ -1468,7 +1471,11 @@ def doc(thing, title='Python Library Documentation: %s', forceload=0): ...@@ -1468,7 +1471,11 @@ def doc(thing, title='Python Library Documentation: %s', forceload=0):
desc += ' in ' + name[:name.rfind('.')] desc += ' in ' + name[:name.rfind('.')]
elif module and module is not object: elif module and module is not object:
desc += ' in module ' + module.__name__ desc += ' in module ' + module.__name__
if not (inspect.ismodule(object) or if type(object) is _OLD_INSTANCE_TYPE:
# If the passed object is an instance of an old-style class,
# document its available methods instead of its value.
object = object.__class__
elif not (inspect.ismodule(object) or
inspect.isclass(object) or inspect.isclass(object) or
inspect.isroutine(object) or inspect.isroutine(object) or
inspect.isgetsetdescriptor(object) or inspect.isgetsetdescriptor(object) or
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment