This thought is motivated by this bug report:
If you import a module, then edit the .py file that goes with it, and then an exception occurs, the stack trace can show the wrong line.
It doesn't happen very often, but when it does happen, it can be very perplexing. Here's a proposal:
When a stack trace is printed, before printing each line, the interpreter checks whether the file's modification time is later than the time recorded in the .pyc file. If the times are different, the stack trace can flag the line and print an addition line stating that the file may have changed and the stack trace may not be accurate.
Something like this perhaps?
Traceback (most recent call last): File "spam.py", line 99, in <spam> eggs.foo() File "eggs.py", line 123, in <eggs> ? for obj in sequence: File "cheese.py", line 456, in <cheese> n = len(x) *** one or more files may have changed *** lines starting with ? may be inaccurate TypeError: object of type 'NoneType' has no len()
I don't think performance will matter. Generating stack traces are rarely performance critical, so I don't think that a few extra file system checks will make any meaningful difference.