Message396204
What I am proposing that pseudofile <SyntaxError> have one line representing a tuple with all the exception information, *including the filename* for the code with the error. In Shell, the filename will usually be another pseudofile name, <pyshell#xx>.
The latter are set with
def stuffsource(self, source):
"Stuff source in the filename cache"
filename = "<pyshell#%d>" % self.gid
self.gid = self.gid + 1
lines = source.split("\n")
linecache.cache[filename] = len(source)+1, 0, lines, filename
return filename
I think the +1 is for a '\n' that will be appended. The linecache line is otherwise our model.
The following is how I created a line <SyntaxError> while testing.
try: compile('a b', '<pyshell#33>', 'single')
except SyntaxError as e:
err = str((type(e).__name__, e.args[0], *e.args[1]))+'\n'
err will be the single line for the file:
"('SyntaxError', 'invalid syntax. Perhaps you forgot a comma?', '<pyshell#33>', 1, 1, 'a b', 1, 4)"
For the patch, err would can be calculated a little differently further down in showsyntaxerror (which needs updating).
Then set the cache with
linecache.cache["<SyntaxError>"] = (len(err), 0, [err], "<SyntaxError>")
---
In friendly, retrieve the lines and unpack the evaluated tuple (\n at the end is ok).
exception, message, filename, line, col, text, line_end, col_end = eval(lines[0])
Use filename to retrieve the error code lines as you wish. |
|
Date |
User |
Action |
Args |
2021-06-21 03:45:57 | terry.reedy | set | recipients:
+ terry.reedy, aroberge |
2021-06-21 03:45:57 | terry.reedy | set | messageid: <1624247157.18.0.430858880121.issue43476@roundup.psfhosted.org> |
2021-06-21 03:45:57 | terry.reedy | link | issue43476 messages |
2021-06-21 03:45:56 | terry.reedy | create | |
|