##// 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 # from its __call__ method.
662 # from its __call__ method.
663
663
664 if inspect.isclass(obj):
664 if inspect.isclass(obj):
665 try:
665 callable_obj = obj.__init__
666 callable_obj = obj.__init__
667 except AttributeError:
668 callable_obj = None
666 elif callable(obj):
669 elif callable(obj):
667 callable_obj = obj
670 callable_obj = obj
668 else:
671 else:
@@ -45,6 +45,10 b' class Call(object):'
45 def method(self, x, z=2):
45 def method(self, x, z=2):
46 """Some method's docstring"""
46 """Some method's docstring"""
47
47
48 class OldStyle:
49 """An old-style class for testing."""
50 pass
51
48 def f(x, y=2, *a, **kw):
52 def f(x, y=2, *a, **kw):
49 """A simple function."""
53 """A simple function."""
50
54
@@ -117,3 +121,11 b' def test_info():'
117 nt.assert_equal(i['class_docstring'], Call.__doc__)
121 nt.assert_equal(i['class_docstring'], Call.__doc__)
118 nt.assert_equal(i['init_docstring'], Call.__init__.__doc__)
122 nt.assert_equal(i['init_docstring'], Call.__init__.__doc__)
119 nt.assert_equal(i['call_docstring'], c.__call__.__doc__)
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