diff --git a/IPython/OInspect.py b/IPython/OInspect.py index f4df4bd..bce9f6e 100644 --- a/IPython/OInspect.py +++ b/IPython/OInspect.py @@ -6,7 +6,7 @@ Uses syntax highlighting for presenting the various information elements. Similar in spirit to the inspect module, but all calls take a name argument to reference the name under which an object is being read. -$Id: OInspect.py 1329 2006-05-26 07:52:45Z fperez $ +$Id: OInspect.py 1571 2006-08-09 07:54:40Z fperez $ """ #***************************************************************************** @@ -30,6 +30,7 @@ import string import StringIO import types import os +import sys # IPython's own from IPython import PyColorize from IPython.genutils import page,indent,Term,mkdict @@ -38,6 +39,45 @@ from IPython.wildcard import list_namespace from IPython.ColorANSI import * #**************************************************************************** +# HACK!!! This is a crude fix for bugs in python 2.3's inspect module. We +# simply monkeypatch inspect with code copied from python 2.4. +if sys.version_info[:2] == (2,3): + from inspect import ismodule, getabsfile, modulesbyfile + def getmodule(object): + """Return the module an object was defined in, or None if not found.""" + if ismodule(object): + return object + if hasattr(object, '__module__'): + return sys.modules.get(object.__module__) + try: + file = getabsfile(object) + except TypeError: + return None + if file in modulesbyfile: + return sys.modules.get(modulesbyfile[file]) + for module in sys.modules.values(): + if hasattr(module, '__file__'): + modulesbyfile[ + os.path.realpath( + getabsfile(module))] = module.__name__ + if file in modulesbyfile: + return sys.modules.get(modulesbyfile[file]) + main = sys.modules['__main__'] + if not hasattr(object, '__name__'): + return None + if hasattr(main, object.__name__): + mainobject = getattr(main, object.__name__) + if mainobject is object: + return main + builtin = sys.modules['__builtin__'] + if hasattr(builtin, object.__name__): + builtinobject = getattr(builtin, object.__name__) + if builtinobject is object: + return builtin + + inspect.getmodule = getmodule + +#**************************************************************************** # Builtin color schemes Colors = TermColors # just a shorthand diff --git a/doc/ChangeLog b/doc/ChangeLog index 114526c..62dde25 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,11 @@ +2006-08-09 Fernando Perez + + * IPython/OInspect.py: monkeypatch inspect from the stdlib if + running under python 2.3 with code from 2.4 to fix a bug with + help(). Reported by the Debian maintainers, Norbert Tretkowski + and Alexandre Fayolle + . + 2006-08-04 Walter Doerwald * IPython/Extensions/ibrowse.py: Fixed the help message in the footer