##// END OF EJS Templates
Tweak Inspector.info() so it doesn't fail on old style classes. Added test....
Thomas Kluyver -
Show More
@@ -662,7 +662,10 b' class Inspector:'
662 662 # from its __call__ method.
663 663
664 664 if inspect.isclass(obj):
665 callable_obj = obj.__init__
665 try:
666 callable_obj = obj.__init__
667 except AttributeError:
668 callable_obj = None
666 669 elif callable(obj):
667 670 callable_obj = obj
668 671 else:
@@ -44,6 +44,10 b' class Call(object):'
44 44
45 45 def method(self, x, z=2):
46 46 """Some method's docstring"""
47
48 class OldStyle:
49 """An old-style class for testing."""
50 pass
47 51
48 52 def f(x, y=2, *a, **kw):
49 53 """A simple function."""
@@ -117,3 +121,11 b' def test_info():'
117 121 nt.assert_equal(i['class_docstring'], Call.__doc__)
118 122 nt.assert_equal(i['init_docstring'], Call.__init__.__doc__)
119 123 nt.assert_equal(i['call_docstring'], c.__call__.__doc__)
124
125 # Test old-style classes, which for example may not have an __init__ method.
126 i = inspector.info(OldStyle)
127 nt.assert_equal(i['type_name'], 'classobj')
128
129 i = inspector.info(OldStyle())
130 nt.assert_equal(i['type_name'], 'instance')
131 nt.assert_equal(i['docstring'], OldStyle.__doc__)
General Comments 0
You need to be logged in to leave comments. Login now