Proporsal: Show an alert in traceback when the source file is newer than compiled code (issue8087)

Hello, I opened this issue a long time ago, and Éric Araujo said that it should be discussed on this list. This is my feature request message: Example: ---------------- mod.py ---------------- def f(): a,b,c = 1,2 print b ---------------------------------------- If i do:
import mod mod.f()
I get: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "mod.py", line 2, in f a,b,c = 1,2 ValueError: need more than 2 values to unpack If i fix the source: ---------------- mod.py ---------------- def f(): a,b,c = 1,2,3 print b ---------------------------------------- And do:
mod.f()
I get: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "mod.py", line 2, in f a,b,c = 1,2,3 ValueError: need more than 2 values to unpack The problem is that the source shown is updated, but the executed code is old, because it wasn't reloaded. Feature request: If the source code shown was modified after import time and it wasn't reloaded, a warning message should be shown. Example: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "mod.py", line 2, in f WARNING: Modified after import! a,b,c = 1,2,3 ValueError: need more than 2 values to unpack or something like that. Thanks, Diego Mascialino

On 7 October 2011 20:53, Diego Mascialino <dmascialino@gmail.com> wrote:
Hello, I opened this issue a long time ago, and Éric Araujo said that it should be discussed on this list.
This is my feature request message:
Example:
---------------- mod.py ---------------- def f(): a,b,c = 1,2 print b ----------------------------------------
If i do:
import mod mod.f()
I get:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "mod.py", line 2, in f a,b,c = 1,2 ValueError: need more than 2 values to unpack
If i fix the source:
---------------- mod.py ---------------- def f(): a,b,c = 1,2,3 print b ----------------------------------------
And do:
mod.f()
I get:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "mod.py", line 2, in f a,b,c = 1,2,3 ValueError: need more than 2 values to unpack
The problem is that the source shown is updated, but the executed code is old, because it wasn't reloaded.
Feature request:
If the source code shown was modified after import time and it wasn't reloaded, a warning message should be shown.
Example:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "mod.py", line 2, in f WARNING: Modified after import! a,b,c = 1,2,3 ValueError: need more than 2 values to unpack
or something like that.
That would mean every function call would need to check the age of the source file and bytecode file on disk and compare! Michael
Thanks, Diego Mascialino _______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
-- http://www.voidspace.org.uk/ May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give. -- the sqlite blessing http://www.sqlite.org/different.html

On 07Oct2011 23:59, Michael Foord <fuzzyman@gmail.com> wrote: | On 7 October 2011 20:53, Diego Mascialino <dmascialino@gmail.com> wrote: | > Hello, I opened this issue a long time ago, and Éric Araujo said that | > it should be discussed on this list. [...] | > The problem is that the source shown is updated, but the executed code | > is old, because it wasn't reloaded. | > | > Feature request: | > | > If the source code shown was modified after import time and it wasn't | > reloaded, a warning message should be shown. | > | > Example: | > | > Traceback (most recent call last): | > File "<stdin>", line 1, in <module> | > File "mod.py", line 2, in f WARNING: Modified after import! | > a,b,c = 1,2,3 | > ValueError: need more than 2 values to unpack | > | > or something like that. | > | | That would mean every function call would need to check the age of the | source file and bytecode file on disk and compare! Only when the traceback was being printed. You would need to stash the modtime at import for later reference. Cheers, -- Cameron Simpson <cs@zip.com.au> DoD#743 http://www.cskk.ezoshosting.com/cs/ Ed Campbell's <ed@Tekelex.Com> pointers for long trips: 2. Figure out the most money you could possibly spend, and take at least double.

On Fri, Oct 7, 2011 at 8:04 PM, Cameron Simpson <cs@zip.com.au> wrote:
Only when the traceback was being printed. You would need to stash the modtime at import for later reference.
Actually the source file modtime there is in the compiled source (.pyc). Import use this information to know if is necessary to compile the source again. In my patch, when a traceback is going to be printed, I compare the actual modtime with the modtime stored in the pyc. Regards, Diego

On Sat, Oct 8, 2011 at 10:37 PM, Diego Mascialino <dmascialino@gmail.com> wrote:
On Fri, Oct 7, 2011 at 8:04 PM, Cameron Simpson <cs@zip.com.au> wrote:
Only when the traceback was being printed. You would need to stash the modtime at import for later reference.
Actually the source file modtime there is in the compiled source (.pyc). Import use this information to know if is necessary to compile the source again.
In my patch, when a traceback is going to be printed, I compare the actual modtime with the modtime stored in the pyc.
Having been caught by this myself on occasion, warning in the traceback certainly sounds like a reasonable hint to provide. I posted a comment to the tracker to that effect (also noting that even with this hint, reloading still has its own problems with stale references to previous incarnation of the module). Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
participants (4)
-
Cameron Simpson
-
Diego Mascialino
-
Michael Foord
-
Nick Coghlan