##// END OF EJS Templates
Merge pull request #1072 from takluyver/i89...
Fernando Perez -
r5574:8a4e8d9b merge
parent child Browse files
Show More
@@ -97,26 +97,22 b' def getdoc(obj):'
97 It also attempts to call a getdoc() method on the given object. This
97 It also attempts to call a getdoc() method on the given object. This
98 allows objects which provide their docstrings via non-standard mechanisms
98 allows objects which provide their docstrings via non-standard mechanisms
99 (like Pyro proxies) to still be inspected by ipython's ? system."""
99 (like Pyro proxies) to still be inspected by ipython's ? system."""
100
101 ds = None # default return value
102 try:
103 ds = inspect.getdoc(obj)
104 except:
105 # Harden against an inspect failure, which can occur with
106 # SWIG-wrapped extensions.
107 pass
108 # Allow objects to offer customized documentation via a getdoc method:
100 # Allow objects to offer customized documentation via a getdoc method:
109 try:
101 try:
110 ds2 = obj.getdoc()
102 ds = obj.getdoc()
111 except:
103 except Exception:
112 pass
104 pass
113 else:
105 else:
114 # if we get extra info, we add it to the normal docstring.
106 # if we get extra info, we add it to the normal docstring.
115 if ds is None:
107 if isinstance(ds, basestring):
116 ds = ds2
108 return inspect.cleandoc(ds)
117 else:
109
118 ds = '%s\n%s' % (ds,ds2)
110 try:
119 return ds
111 return inspect.getdoc(obj)
112 except Exception:
113 # Harden against an inspect failure, which can occur with
114 # SWIG-wrapped extensions.
115 return None
120
116
121
117
122 def getsource(obj,is_binary=False):
118 def getsource(obj,is_binary=False):
@@ -134,3 +134,26 b' def test_info():'
134 i = inspector.info(OldStyle())
134 i = inspector.info(OldStyle())
135 nt.assert_equal(i['type_name'], 'instance')
135 nt.assert_equal(i['type_name'], 'instance')
136 nt.assert_equal(i['docstring'], OldStyle.__doc__)
136 nt.assert_equal(i['docstring'], OldStyle.__doc__)
137
138 def test_getdoc():
139 class A(object):
140 """standard docstring"""
141 pass
142
143 class B(object):
144 """standard docstring"""
145 def getdoc(self):
146 return "custom docstring"
147
148 class C(object):
149 """standard docstring"""
150 def getdoc(self):
151 return None
152
153 a = A()
154 b = B()
155 c = C()
156
157 nt.assert_equal(oinspect.getdoc(a), "standard docstring")
158 nt.assert_equal(oinspect.getdoc(b), "custom docstring")
159 nt.assert_equal(oinspect.getdoc(c), "standard docstring")
General Comments 0
You need to be logged in to leave comments. Login now