##// END OF EJS Templates
handle multiple decorators in oinspect...
Min RK -
Show More
@@ -201,10 +201,7 b" def getsource(obj, oname=''):"
201 else:
201 else:
202 # Get source for non-property objects.
202 # Get source for non-property objects.
203
203
204 # '__wrapped__' attribute is used by some decorators (e.g. ones defined
204 obj = _get_wrapped(obj)
205 # functools) to provide access to the decorated function.
206 if hasattr(obj, "__wrapped__"):
207 obj = obj.__wrapped__
208
205
209 try:
206 try:
210 src = inspect.getsource(obj)
207 src = inspect.getsource(obj)
@@ -303,6 +300,12 b' def call_tip(oinfo, format_call=True):'
303 return call_line, doc
300 return call_line, doc
304
301
305
302
303 def _get_wrapped(obj):
304 """Get the original object if wrapped in one or more @decorators"""
305 while safe_hasattr(obj, '__wrapped__'):
306 obj = obj.__wrapped__
307 return obj
308
306 def find_file(obj):
309 def find_file(obj):
307 """Find the absolute path to the file where an object was defined.
310 """Find the absolute path to the file where an object was defined.
308
311
@@ -319,9 +322,7 b' def find_file(obj):'
319 fname : str
322 fname : str
320 The absolute path to the file where the object was defined.
323 The absolute path to the file where the object was defined.
321 """
324 """
322 # get source if obj was decorated with @decorator
325 obj = _get_wrapped(obj)
323 if safe_hasattr(obj, '__wrapped__'):
324 obj = obj.__wrapped__
325
326
326 fname = None
327 fname = None
327 try:
328 try:
@@ -356,9 +357,7 b' def find_source_lines(obj):'
356 lineno : int
357 lineno : int
357 The line number where the object definition starts.
358 The line number where the object definition starts.
358 """
359 """
359 # get source if obj was decorated with @decorator
360 obj = _get_wrapped(obj)
360 if safe_hasattr(obj, '__wrapped__'):
361 obj = obj.__wrapped__
362
361
363 try:
362 try:
364 try:
363 try:
@@ -92,6 +92,8 b' def test_find_file_decorated2():'
92 return f(*a, **kw)
92 return f(*a, **kw)
93
93
94 @noop2
94 @noop2
95 @noop2
96 @noop2
95 def f(x):
97 def f(x):
96 "My docstring 2"
98 "My docstring 2"
97
99
General Comments 0
You need to be logged in to leave comments. Login now