@@ -116,12 +116,25 @@ def print_source_location_info(
116116 print_fn (mess )
117117 return
118118
119-
120119def print_location (proc_obj ):
121120 """Show where we are. GUI's and front-end interfaces often
122121 use this to update displays. So it is helpful to make sure
123122 we give at least some place that's located in a file.
124123 """
124+
125+ def prefix_for_filename (deparsed_text : str ) -> str :
126+ """
127+ Return a reasonable filename-friendly string from some
128+ deparsed text. We do this so that the user gets some idea of
129+ what the string (source code text) is contained in the file.
130+
131+ """
132+ lines = deparsed_text .split ("\n " )
133+ # FIXME Rather than blindly take the first line,
134+ # check if it is blank and if so use other lines.
135+ first_text_line = lines [0 ]
136+ return proc_obj ._saferepr (first_text_line )[1 :- 1 ][:10 ]
137+
125138 i_stack = proc_obj .curindex
126139 if i_stack is None or proc_obj .stack is None :
127140 return False
@@ -176,11 +189,8 @@ def print_location(proc_obj):
176189 if deparsed :
177190 # Create a nice prefix for the temporary file to write.
178191 # Use the exec type and first line of the deparsed text.
179- first_text_line = deparsed .text .split ("\n " )[0 ]
180- # Strip of quotes added by repr and up the first 10 characters
181- # of result.
182- leading_code = proc_obj ._saferepr (first_text_line )[1 :- 1 ][:10 ]
183- prefix = f"{ eval_kind } -{ leading_code } -"
192+ leading_code_str = prefix_for_filename (deparsed .text )
193+ prefix = f"{ eval_kind } -{ leading_code_str } -"
184194
185195 remapped_file = cmdfns .source_tempfile_remap (
186196 prefix ,
@@ -192,6 +202,11 @@ def print_location(proc_obj):
192202 filename = remapped_file
193203 else :
194204 eval_kind = is_eval_or_exec_stmt (frame )
205+ deparsed = deparse_fn (frame .f_code )
206+ if deparsed is not None :
207+ source_text = deparsed .text
208+ # else:
209+ # print("Can't deparse", frame.f_code)
195210 if source_text is None and eval_kind :
196211 source_text = f"{ eval_kind } (...)"
197212 pass
@@ -251,7 +266,7 @@ def print_location(proc_obj):
251266 # FIXME:
252267 if source_text :
253268 lines = source_text .split ("\n " )
254- temp_name = "string-"
269+ temp_name = "string-" + prefix_for_filename ( source_text )
255270 else :
256271 # try with good ol linecache and consider fixing pyficache
257272 lines = linecache .getlines (filename )
0 commit comments