[Python-ideas] Stack traces ought to flag when a module has been changed on disk

Pradyun Gedam pradyunsg at gmail.com
Wed Jan 30 05:41:11 EST 2019


On Wed, 30 Jan 2019 at 3:48 PM, Steven D'Aprano <steve at pearwood.info> wrote:

> This thought is motivated by this bug report:
>
> https://bugs.python.org/issue35857
>
> 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.
>
>
> Thoughts?


I like this idea. A variation would be to just
add " (modified)" to the file name - line number bits of the stack trace,
for the appropriate files.

--
Pradyun

>
>
>
>
> --
> Steve
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190130/c26a8262/attachment.html>


More information about the Python-ideas mailing list