Try to fix the filenames in each record from inspect.getinnerframes(). Particularly, modules loaded from within zip files have useless filenames attached to their code object, and inspect.getinnerframes() just uses it.
(records)
| 322 | |
| 323 | |
| 324 | def fix_frame_records_filenames(records): |
| 325 | """Try to fix the filenames in each record from inspect.getinnerframes(). |
| 326 | |
| 327 | Particularly, modules loaded from within zip files have useless filenames |
| 328 | attached to their code object, and inspect.getinnerframes() just uses it. |
| 329 | """ |
| 330 | fixed_records = [] |
| 331 | for frame, filename, line_no, func_name, lines, index in records: |
| 332 | # Look inside the frame's globals dictionary for __file__, |
| 333 | # which should be better. However, keep Cython filenames since |
| 334 | # we prefer the source filenames over the compiled .so file. |
| 335 | if not filename.endswith(('.pyx', '.pxd', '.pxi')): |
| 336 | better_fn = frame.f_globals.get('__file__', None) |
| 337 | if isinstance(better_fn, str): |
| 338 | # Check the type just in case someone did something weird with |
| 339 | # __file__. It might also be None if the error occurred during |
| 340 | # import. |
| 341 | filename = better_fn |
| 342 | fixed_records.append((frame, filename, line_no, func_name, lines, index)) |
| 343 | return fixed_records |
| 344 | |
| 345 | |
| 346 | @with_patch_inspect |
no outgoing calls
no test coverage detected