From 7f0a0f4e82db1adf34086405f7d341f73f709dd6 2013-10-29 16:15:55 From: Thomas Kluyver Date: 2013-10-29 16:15:55 Subject: [PATCH] Fix method special attributes 2to3 fixer: methodattrs --- diff --git a/IPython/core/magics/basic.py b/IPython/core/magics/basic.py index f45e541..c3dbbb4 100644 --- a/IPython/core/magics/basic.py +++ b/IPython/core/magics/basic.py @@ -72,7 +72,7 @@ class MagicsDisplay(object): magic_dict[key] = d for name, obj in subdict.items(): try: - classname = obj.im_class.__name__ + classname = obj.__self__.__class__.__name__ except AttributeError: classname = 'Other' diff --git a/IPython/core/oinspect.py b/IPython/core/oinspect.py index 0802bdc..d71795a 100644 --- a/IPython/core/oinspect.py +++ b/IPython/core/oinspect.py @@ -188,7 +188,7 @@ def getargspec(obj): if inspect.isfunction(obj): func_obj = obj elif inspect.ismethod(obj): - func_obj = obj.im_func + func_obj = obj.__func__ elif hasattr(obj, '__call__'): func_obj = obj.__call__ else: diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index 09b6486..e438cff 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -834,9 +834,9 @@ def test_multiple_magics(): foo2 = FooFoo(ip) mm = ip.magics_manager mm.register(foo1) - nt.assert_true(mm.magics['line']['foo'].im_self is foo1) + nt.assert_true(mm.magics['line']['foo'].__self__ is foo1) mm.register(foo2) - nt.assert_true(mm.magics['line']['foo'].im_self is foo2) + nt.assert_true(mm.magics['line']['foo'].__self__ is foo2) def test_alias_magic(): """Test %alias_magic.""" diff --git a/IPython/core/ultratb.py b/IPython/core/ultratb.py index 0fcb028..8ea0874 100644 --- a/IPython/core/ultratb.py +++ b/IPython/core/ultratb.py @@ -196,7 +196,7 @@ def findsource(object): raise IOError('could not find class definition') if ismethod(object): - object = object.im_func + object = object.__func__ if isfunction(object): object = object.__code__ if istraceback(object): diff --git a/IPython/extensions/autoreload.py b/IPython/extensions/autoreload.py index f1cec38..35a7bd0 100644 --- a/IPython/extensions/autoreload.py +++ b/IPython/extensions/autoreload.py @@ -308,7 +308,7 @@ else: UPDATE_RULES.extend([(lambda a, b: isinstance2(a, b, types.ClassType), update_class), (lambda a, b: isinstance2(a, b, types.MethodType), - lambda a, b: update_function(a.im_func, b.im_func)), + lambda a, b: update_function(a.__func__, b.__func__)), ]) diff --git a/IPython/testing/plugin/ipdoctest.py b/IPython/testing/plugin/ipdoctest.py index 42438c5..1f86a1c 100644 --- a/IPython/testing/plugin/ipdoctest.py +++ b/IPython/testing/plugin/ipdoctest.py @@ -109,7 +109,7 @@ class DocTestFinder(doctest.DocTestFinder): # __module__ attribute of methods, but since the same error is easy # to make by extension code writers, having this safety in place # isn't such a bad idea - return module.__name__ == object.im_class.__module__ + return module.__name__ == object.__self__.__class__.__module__ elif inspect.getmodule(object) is not None: return module is inspect.getmodule(object) elif hasattr(object, '__module__'): @@ -157,7 +157,7 @@ class DocTestFinder(doctest.DocTestFinder): if isinstance(val, staticmethod): val = getattr(obj, valname) if isinstance(val, classmethod): - val = getattr(obj, valname).im_func + val = getattr(obj, valname).__func__ # Recurse to methods, properties, and nested classes. if ((inspect.isfunction(val) or inspect.isclass(val) or diff --git a/IPython/testing/tests/test_decorators.py b/IPython/testing/tests/test_decorators.py index 295bd5e..9b3998f 100644 --- a/IPython/testing/tests/test_decorators.py +++ b/IPython/testing/tests/test_decorators.py @@ -33,7 +33,7 @@ def getargspec(obj): if inspect.isfunction(obj): func_obj = obj elif inspect.ismethod(obj): - func_obj = obj.im_func + func_obj = obj.__func__ else: raise TypeError('arg is not a Python function') args, varargs, varkw = inspect.getargs(func_obj.__code__)