Show More
@@ -246,12 +246,16 b' def find_file(obj):' | |||
|
246 | 246 | fname : str |
|
247 | 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 | 253 | try: |
|
250 | 254 | fname = inspect.getabsfile(obj) |
|
251 | 255 | except TypeError: |
|
252 | 256 | # For an instance, the file that matters is where its class was |
|
253 | 257 | # declared. |
|
254 | if hasattr(obj,'__class__'): | |
|
258 | if hasattr(obj, '__class__'): | |
|
255 | 259 | try: |
|
256 | 260 | fname = inspect.getabsfile(obj.__class__) |
|
257 | 261 | except TypeError: |
@@ -259,10 +263,6 b' def find_file(obj):' | |||
|
259 | 263 | fname = None |
|
260 | 264 | except: |
|
261 | 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 | 266 | return fname |
|
267 | 267 | |
|
268 | 268 | |
@@ -282,19 +282,17 b' def find_source_lines(obj):' | |||
|
282 | 282 | lineno : int |
|
283 | 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 | 289 | try: |
|
286 | 290 | try: |
|
287 | 291 | lineno = inspect.getsourcelines(obj)[1] |
|
288 | 292 | except TypeError: |
|
289 | 293 | # For instances, try the class object like getsource() does |
|
290 | if hasattr(obj,'__class__'): | |
|
294 | if hasattr(obj, '__class__'): | |
|
291 | 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 | 296 | except: |
|
299 | 297 | return None |
|
300 | 298 |
General Comments 0
You need to be logged in to leave comments.
Login now