Logged In: YES
user_id=6133
OK, I've done some more investigation and have some more details and
clarification. I've attached another python script that demonstrates these
additional clarifications:
First, it runs sample scripts in a test directory. The sample scripts generate an
exception, print that exception with traceback.print_exc, then raise to let the
interpreter print the exception as it fails the script. The control script
verifies that the output of traceback.print_exc matches the interpreter's
traceback output. So far, so good.
Step two demonstrates the first problem: the original directory is simply
renamed; the previous location does not exist. The same sample scripts are
run, and the output now shows that traceback.print_exc() output is
*different* than the interpreter's traceback. Specifically, the interpreter
prints the new, correct path, but the traceback.print_exc() prints the old
path.
Step three demonstrates another problem. The scripts are run from the new
directory, but the old directory now exists, along files having the original .py
names, but those files are now much shorter; the lines that will be referenced
in the traceback do not exist. In the output from this step, note that the
output from traceback.print_exc() and the interpreter traceback are again
*different* from each other. In this case, both are fooled into reporting file
paths in the old directory, but for a non-existent line the interpreter prints a
blank line but traceback.print_exc() doesn't print a line at all.
And finally, the .py files in the original directory are filled with nonsense (in
python terms). This test case shows that the output from traceback.
print_exc() and the interpreter *do match*, but both are fooled into showing
file paths in the old directory and the nonsense from the new versions of the
files.
IMHO, I think that the output from the traceback.print_exc() and the
interpreter traceback should be the same in *all* scenarios, and I also think
that the path used for importing the module should be used in traceback
reporting.
Rather than encoding the full path of the .py source in the .pyc, the compiler
should just encode the name portion, and use the path from the .pyc import
and look for the .py in the same directory as the .pyc; if that's garbage, then
so be it, but this will 99% of the time be more correct than the current
behavior.
|