Xavier de Gaye added the comment:
This is a simple code object compiled from a source (the string), a module is
quite different and more complex. The patch uses a fake module Loader to use
linecache, there is no gain in going any further and pulling from the importlib
machinery, I think.
Pinku Surana added the comment:
Thanks. This is clever. I've tried it out and it works. Would it be more
appropriate to use "importlib" and "importlib.abc" to implement a custom loader
for a string script? It looks like importlib.abc.InspectLoader does the right
thing.
--
___
Xavier de Gaye added the comment:
This patch is an attempt at allowing the source debugging of scripts executed
by the Python exec() function. It misses tests and documentation.
You may use it using the idiom given in the following example to avoid stepping
into the pdb code on the first invoc
Xavier de Gaye added the comment:
The lazycache() function of the linecache module meets your request, I think.
See the following debugging session using the attached script:
$ python -m pdb debug_script.py
> /path/to/cwd/debug_script.py(1)()
-> def debug_script(script):
(Pdb) n
> /path/to/cwd/
New submission from Pinku Surana:
I am using Python as a hosted scripting runtime for a product. All the user
scripts are stored in a database. I use "compile" and "exec" to run the
scripts. I'd like to use PDB to debug scripts. Unfortunately, PDB makes a call
to linecache, which calls tokeniz