##// END OF EJS Templates
Promote __wrapped__ logic to the top as per review.
Fernando Perez -
Show More
@@ -246,12 +246,16 b' def find_file(obj):'
246 fname : str
246 fname : str
247 The absolute path to the file where the object was defined.
247 The absolute path to the file where the object was defined.
248 """
248 """
249 # get source if obj was decorated with @decorator
250 if hasattr(obj, '__wrapped__'):
251 obj = obj.__wrapped__
252
249 try:
253 try:
250 fname = inspect.getabsfile(obj)
254 fname = inspect.getabsfile(obj)
251 except TypeError:
255 except TypeError:
252 # For an instance, the file that matters is where its class was
256 # For an instance, the file that matters is where its class was
253 # declared.
257 # declared.
254 if hasattr(obj,'__class__'):
258 if hasattr(obj, '__class__'):
255 try:
259 try:
256 fname = inspect.getabsfile(obj.__class__)
260 fname = inspect.getabsfile(obj.__class__)
257 except TypeError:
261 except TypeError:
@@ -259,10 +263,6 b' def find_file(obj):'
259 fname = None
263 fname = None
260 except:
264 except:
261 fname = None
265 fname = None
262 else:
263 if fname.endswith('<string>') and hasattr(obj, '__wrapped__'):
264 # Analyze decorated functions and methods correctly
265 fname = inspect.getabsfile(obj.__wrapped__)
266 return fname
266 return fname
267
267
268
268
@@ -282,19 +282,17 b' def find_source_lines(obj):'
282 lineno : int
282 lineno : int
283 The line number where the object definition starts.
283 The line number where the object definition starts.
284 """
284 """
285 # get source if obj was decorated with @decorator
286 if hasattr(obj, '__wrapped__'):
287 obj = obj.__wrapped__
288
285 try:
289 try:
286 try:
290 try:
287 lineno = inspect.getsourcelines(obj)[1]
291 lineno = inspect.getsourcelines(obj)[1]
288 except TypeError:
292 except TypeError:
289 # For instances, try the class object like getsource() does
293 # For instances, try the class object like getsource() does
290 if hasattr(obj,'__class__'):
294 if hasattr(obj, '__class__'):
291 lineno = inspect.getsourcelines(obj.__class__)[1]
295 lineno = inspect.getsourcelines(obj.__class__)[1]
292 # Adjust the inspected object so getabsfile() below works
293 obj = obj.__class__
294 except IOError:
295 if hasattr(obj, '__wrapped__'):
296 obj = obj.__wrapped__
297 lineno = inspect.getsourcelines(obj)[1]
298 except:
296 except:
299 return None
297 return None
300
298
General Comments 0
You need to be logged in to leave comments. Login now