diff --git a/IPython/core/oinspect.py b/IPython/core/oinspect.py index e8bc4dc..48631f3 100644 --- a/IPython/core/oinspect.py +++ b/IPython/core/oinspect.py @@ -662,7 +662,8 @@ class Inspector: # from its __call__ method. if inspect.isclass(obj): - callable_obj = obj.__init__ + # Old-style classes need not have an __init__ + callable_obj = getattr(obj, "__init__", None) elif callable(obj): callable_obj = obj else: diff --git a/IPython/core/tests/test_oinspect.py b/IPython/core/tests/test_oinspect.py index f110250..c3f7a2f 100644 --- a/IPython/core/tests/test_oinspect.py +++ b/IPython/core/tests/test_oinspect.py @@ -44,6 +44,10 @@ class Call(object): def method(self, x, z=2): """Some method's docstring""" + +class OldStyle: + """An old-style class for testing.""" + pass def f(x, y=2, *a, **kw): """A simple function.""" @@ -117,3 +121,11 @@ def test_info(): nt.assert_equal(i['class_docstring'], Call.__doc__) nt.assert_equal(i['init_docstring'], Call.__init__.__doc__) nt.assert_equal(i['call_docstring'], c.__call__.__doc__) + + # Test old-style classes, which for example may not have an __init__ method. + i = inspector.info(OldStyle) + nt.assert_equal(i['type_name'], 'classobj') + + i = inspector.info(OldStyle()) + nt.assert_equal(i['type_name'], 'instance') + nt.assert_equal(i['docstring'], OldStyle.__doc__)