##// END OF EJS Templates
fix help() bug when running under python 2.3
fperez -
Show More
@@ -6,7 +6,7 b' Uses syntax highlighting for presenting the various information elements.'
6 Similar in spirit to the inspect module, but all calls take a name argument to
6 Similar in spirit to the inspect module, but all calls take a name argument to
7 reference the name under which an object is being read.
7 reference the name under which an object is being read.
8
8
9 $Id: OInspect.py 1329 2006-05-26 07:52:45Z fperez $
9 $Id: OInspect.py 1571 2006-08-09 07:54:40Z fperez $
10 """
10 """
11
11
12 #*****************************************************************************
12 #*****************************************************************************
@@ -30,6 +30,7 b' import string'
30 import StringIO
30 import StringIO
31 import types
31 import types
32 import os
32 import os
33 import sys
33 # IPython's own
34 # IPython's own
34 from IPython import PyColorize
35 from IPython import PyColorize
35 from IPython.genutils import page,indent,Term,mkdict
36 from IPython.genutils import page,indent,Term,mkdict
@@ -38,6 +39,45 b' from IPython.wildcard import list_namespace'
38 from IPython.ColorANSI import *
39 from IPython.ColorANSI import *
39
40
40 #****************************************************************************
41 #****************************************************************************
42 # HACK!!! This is a crude fix for bugs in python 2.3's inspect module. We
43 # simply monkeypatch inspect with code copied from python 2.4.
44 if sys.version_info[:2] == (2,3):
45 from inspect import ismodule, getabsfile, modulesbyfile
46 def getmodule(object):
47 """Return the module an object was defined in, or None if not found."""
48 if ismodule(object):
49 return object
50 if hasattr(object, '__module__'):
51 return sys.modules.get(object.__module__)
52 try:
53 file = getabsfile(object)
54 except TypeError:
55 return None
56 if file in modulesbyfile:
57 return sys.modules.get(modulesbyfile[file])
58 for module in sys.modules.values():
59 if hasattr(module, '__file__'):
60 modulesbyfile[
61 os.path.realpath(
62 getabsfile(module))] = module.__name__
63 if file in modulesbyfile:
64 return sys.modules.get(modulesbyfile[file])
65 main = sys.modules['__main__']
66 if not hasattr(object, '__name__'):
67 return None
68 if hasattr(main, object.__name__):
69 mainobject = getattr(main, object.__name__)
70 if mainobject is object:
71 return main
72 builtin = sys.modules['__builtin__']
73 if hasattr(builtin, object.__name__):
74 builtinobject = getattr(builtin, object.__name__)
75 if builtinobject is object:
76 return builtin
77
78 inspect.getmodule = getmodule
79
80 #****************************************************************************
41 # Builtin color schemes
81 # Builtin color schemes
42
82
43 Colors = TermColors # just a shorthand
83 Colors = TermColors # just a shorthand
@@ -1,3 +1,11 b''
1 2006-08-09 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * IPython/OInspect.py: monkeypatch inspect from the stdlib if
4 running under python 2.3 with code from 2.4 to fix a bug with
5 help(). Reported by the Debian maintainers, Norbert Tretkowski
6 <norbert-AT-tretkowski.de> and Alexandre Fayolle
7 <afayolle-AT-debian.org>.
8
1 2006-08-04 Walter Doerwald <walter@livinglogic.de>
9 2006-08-04 Walter Doerwald <walter@livinglogic.de>
2
10
3 * IPython/Extensions/ibrowse.py: Fixed the help message in the footer
11 * IPython/Extensions/ibrowse.py: Fixed the help message in the footer
General Comments 0
You need to be logged in to leave comments. Login now