diff options
author | Ka-Ping Yee <ping@zesty.ca> | 2007-01-14 04:25:15 +0000 |
---|---|---|
committer | Ka-Ping Yee <ping@zesty.ca> | 2007-01-14 04:25:15 +0000 |
commit | 8ef1cf30b7a3427c42fe803547c6f7f33187783f (patch) | |
tree | 01d5248d5549a41ecf8f69d2665951e7be455d29 /Lib/pydoc.py | |
parent | 0567ba20f3a9f43c105ad91d8a19f23d7640fac3 (diff) | |
download | cpython-git-8ef1cf30b7a3427c42fe803547c6f7f33187783f.tar.gz |
Handle old-style instances more gracefully (display documentation on
the relevant class instead of documentation on <type 'instance'>).
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-x | Lib/pydoc.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py index ce9751787b..94927d0270 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1448,6 +1448,9 @@ def locate(path, forceload=0): text = TextDoc() html = HTMLDoc() +class _OldStyleClass: pass +_OLD_INSTANCE_TYPE = type(_OldStyleClass()) + def resolve(thing, forceload=0): """Given an object or a path to an object, get the object and its name.""" if isinstance(thing, str): @@ -1468,12 +1471,16 @@ def doc(thing, title='Python Library Documentation: %s', forceload=0): desc += ' in ' + name[:name.rfind('.')] elif module and module is not object: desc += ' in module ' + module.__name__ - if not (inspect.ismodule(object) or - inspect.isclass(object) or - inspect.isroutine(object) or - inspect.isgetsetdescriptor(object) or - inspect.ismemberdescriptor(object) or - isinstance(object, property)): + 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.isroutine(object) or + inspect.isgetsetdescriptor(object) or + inspect.ismemberdescriptor(object) or + isinstance(object, property)): # If the passed object is a piece of data or an instance, # document its available methods instead of its value. object = type(object) |