diff --git a/IPython/FakeModule.py b/IPython/FakeModule.py index 39253eb..19f1746 100644 --- a/IPython/FakeModule.py +++ b/IPython/FakeModule.py @@ -5,7 +5,7 @@ Class which mimics a module. Needed to allow pickle to correctly resolve namespaces during IPython sessions. -$Id: FakeModule.py 1322 2006-05-24 07:51:39Z fperez $""" +$Id: FakeModule.py 1602 2006-08-11 09:19:33Z vivainio $""" #***************************************************************************** # Copyright (C) 2002-2004 Fernando Perez. @@ -14,7 +14,9 @@ $Id: FakeModule.py 1322 2006-05-24 07:51:39Z fperez $""" # the file COPYING, distributed as part of this software. #***************************************************************************** -class FakeModule: +import types + +class FakeModule(types.ModuleType): """Simple class with attribute access to fake a module. This is not meant to replace a module, but to allow inserting a fake @@ -25,7 +27,7 @@ class FakeModule: Do NOT use this code for anything other than this IPython private hack.""" def __init__(self,adict): - + types.ModuleType.__init__(self,adict['__name__']) # It seems pydoc (and perhaps others) needs any module instance to # implement a __nonzero__ method, so we add it if missing: if '__nonzero__' not in adict: @@ -33,17 +35,16 @@ class FakeModule: return 1 adict['__nonzero__'] = __nonzero__ - self.__dict__ = adict - # modules should have a __file__ attribute adict['__file__'] = __file__ + self.__origdict = adict def __getattr__(self,key): - try: - return self.__dict__[key] - except KeyError, e: - raise AttributeError("FakeModule object has no attribute %s" % e) - + try: + return self.__origdict[key] + except KeyError, e: + raise AttributeError("FakeModule object has no attribute %s" % e) + def __str__(self): return "" diff --git a/IPython/OInspect.py b/IPython/OInspect.py index bce9f6e..e5292a2 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 1571 2006-08-09 07:54:40Z fperez $ +$Id: OInspect.py 1602 2006-08-11 09:19:33Z vivainio $ """ #***************************************************************************** @@ -30,7 +30,6 @@ 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 @@ -39,45 +38,6 @@ 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 62dde25..aaa410b 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,10 @@ +2006-08-11 Ville Vainio + + * Fakemodule.py, OInspect.py: remove 2006-08-09 monkepatch + by resolving issue properly, i.e. by inheriting FakeModule + from types.ModuleType. Pickling ipython interactive data + should still work as usual (testing appreciated). + 2006-08-09 Fernando Perez * IPython/OInspect.py: monkeypatch inspect from the stdlib if