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 p
(obj)
| 315 | return obj |
| 316 | |
| 317 | def find_file(obj) -> Optional[str]: |
| 318 | """Find the absolute path to the file where an object was defined. |
| 319 | |
| 320 | This is essentially a robust wrapper around `inspect.getabsfile`. |
| 321 | |
| 322 | Returns None if no file can be found. |
| 323 | |
| 324 | Parameters |
| 325 | ---------- |
| 326 | obj : any Python object |
| 327 | |
| 328 | Returns |
| 329 | ------- |
| 330 | fname : str |
| 331 | The absolute path to the file where the object was defined. |
| 332 | """ |
| 333 | obj = _get_wrapped(obj) |
| 334 | |
| 335 | fname: Optional[str] = None |
| 336 | try: |
| 337 | fname = inspect.getabsfile(obj) |
| 338 | except TypeError: |
| 339 | # For an instance, the file that matters is where its class was |
| 340 | # declared. |
| 341 | try: |
| 342 | fname = inspect.getabsfile(obj.__class__) |
| 343 | except (OSError, TypeError): |
| 344 | # Can happen for builtins |
| 345 | pass |
| 346 | except OSError: |
| 347 | pass |
| 348 | |
| 349 | return fname |
| 350 | |
| 351 | |
| 352 | def find_source_lines(obj): |
no test coverage detected
searching dependent graphs…