Find the absolute path to the file where an object was defined. This is essentially a robust wrapper around `inspect.getabsfile`. Returns None if no file can be found. Parameters ---------- obj : any Python object Returns ------- fname : str The absolute pat
(obj)
| 285 | return obj |
| 286 | |
| 287 | def find_file(obj) -> str: |
| 288 | """Find the absolute path to the file where an object was defined. |
| 289 | |
| 290 | This is essentially a robust wrapper around `inspect.getabsfile`. |
| 291 | |
| 292 | Returns None if no file can be found. |
| 293 | |
| 294 | Parameters |
| 295 | ---------- |
| 296 | obj : any Python object |
| 297 | |
| 298 | Returns |
| 299 | ------- |
| 300 | fname : str |
| 301 | The absolute path to the file where the object was defined. |
| 302 | """ |
| 303 | obj = _get_wrapped(obj) |
| 304 | |
| 305 | fname = None |
| 306 | try: |
| 307 | fname = inspect.getabsfile(obj) |
| 308 | except TypeError: |
| 309 | # For an instance, the file that matters is where its class was |
| 310 | # declared. |
| 311 | if hasattr(obj, '__class__'): |
| 312 | try: |
| 313 | fname = inspect.getabsfile(obj.__class__) |
| 314 | except TypeError: |
| 315 | # Can happen for builtins |
| 316 | pass |
| 317 | except: |
| 318 | pass |
| 319 | return cast_unicode(fname) |
| 320 | |
| 321 | |
| 322 | def find_source_lines(obj): |
no test coverage detected