|
22 | 22 | import linecache |
23 | 23 | import os |
24 | 24 | import os.path as osp |
| 25 | +import pyficache |
25 | 26 | import re |
26 | | -from dataclasses import dataclass |
| 27 | + |
27 | 28 | from opcode import opname |
28 | 29 | from reprlib import repr |
29 | 30 | from types import CodeType, FrameType |
@@ -67,8 +68,7 @@ def deparse_offset(_code, _name: str, _list_i: int, _) -> tuple: |
67 | 68 |
|
68 | 69 | opc = xdis.get_opcode_module(PYTHON_VERSION_TRIPLE, PYTHON_IMPLEMENTATION) |
69 | 70 |
|
70 | | -# A mapping frame to its ExtraFrameInfo. This is a weak dictionary so that |
71 | | -# frames are automatically removed. |
| 71 | +# A mapping frame to its ExtraFrameInfo. |
72 | 72 | FrameInfo: Dict[FrameType, int] = {} |
73 | 73 |
|
74 | 74 | def count_frames(frame: FrameType) -> int: |
@@ -227,7 +227,12 @@ def format_function_and_parameters( |
227 | 227 | else: |
228 | 228 | is_module = False |
229 | 229 | try: |
230 | | - params = inspect.formatargvalues(args, varargs, varkw, local_vars) |
| 230 | + if is_eval_or_exec_stmt(frame): |
| 231 | + # Nuke the function name |
| 232 | + s = "" |
| 233 | + params = get_exec_or_eval_string(frame) |
| 234 | + else: |
| 235 | + params = inspect.formatargvalues(args, varargs, varkw, local_vars) |
231 | 236 | formatted_params = format_python(params, style=style) |
232 | 237 | except Exception: |
233 | 238 | pass |
@@ -271,12 +276,14 @@ def format_return_and_location( |
271 | 276 | if include_location: |
272 | 277 | is_pseudo_file = _re_pseudo_file.match(filename) |
273 | 278 | add_quotes_around_file = not is_pseudo_file |
274 | | - if is_module: |
275 | | - if filename == "<string>": |
276 | | - if (func_name := is_eval_or_exec_stmt(frame)): |
277 | | - s += f" in {func_name}" |
278 | | - elif not is_eval_or_exec_stmt(frame) and not is_pseudo_file: |
279 | | - s += " file" |
| 279 | + # FIXME: DRY |
| 280 | + if filename == "<string>": |
| 281 | + if (func_name := is_eval_or_exec_stmt(frame)): |
| 282 | + s += f" in {func_name}" |
| 283 | + if remapped_filename := pyficache.main.code2tempfile.get(frame.f_code): |
| 284 | + filename = remapped_filename |
| 285 | + elif not is_eval_or_exec_stmt(frame) and not is_pseudo_file: |
| 286 | + s += " file" |
280 | 287 | elif s == "?()": |
281 | 288 | if (func_name := is_eval_or_exec_stmt(frame)): |
282 | 289 | s = f"in {func_name}" |
@@ -677,6 +684,9 @@ def fn(x): |
677 | 684 | dd, (frame.f_back, frame.f_back.f_code.co_firstlineno, -1) |
678 | 685 | ) |
679 | 686 | ) |
| 687 | + dd.core.processor.curframe = frame.f_back |
| 688 | + dd.core.processor.stack = [(dd.core.processor.curframe, 1, 0)] |
| 689 | + print_stack_entry(dd.core.processor, 0) |
680 | 690 |
|
681 | 691 | _, mess = format_function_and_parameters(frame, dd, style="tango") |
682 | 692 | print(mess) |
|
0 commit comments