[issue8087] Unupdated source file in traceback
Diego Mascialino added the comment: I worked a few hours today and I have this patch. I tried to make a test but could not. I know this is not a really good patch, but it's my first one and I wanted to show my idea. -- keywords: +patch versions: -Python 2.7 Added file: http://bugs.python.org/file23321/issue8087.patch ___ Python tracker <http://bugs.python.org/issue8087> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8087] Unupdated source file in traceback
Diego Mascialino added the comment: On Fri, Oct 7, 2011 at 5:25 PM, Ezio Melotti wrote: > > Ezio Melotti added the comment: > > I'm not sure this is useful to have. If you changed your code you know that > you have to reload, so why would you want a warning that tells you that you > changed the code? The source line showed in the traceback could not be the same line executed. Take a look to this example: k.py: def f(): a,b,c = 1,2 Traceback (most recent call last): File "", line 1, in File "k.py", line 2, in f a,b,c = 1,2 ValueError: need more than 2 values to unpack k.py: def f(): # blah a,b = 1,2 Traceback (most recent call last): File "", line 1, in File "k.py", line 2, in f # blah ValueError: need more than 2 values to unpack > For some reason I always had the opposite problem (i.e. after a reload the > traceback was still showing the original code, and not the new one), while > IIUC you are saying that it shows the new code even if the module is not > reloaded. > I tried your code and indeed it does what you say, so either I am mistaken > and I've been misreading the tracebacks, or this changed from 2.6 to 2.7, or > in some cases even the behavior (I think) I observed might happen. > I'll have to verify this next time it happens. That is strange, I think Python does not save the original code in any place. -- ___ Python tracker <http://bugs.python.org/issue8087> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8087] Unupdated source file in traceback
Diego Mascialino added the comment: > So to me, your warning will only be useful in the case where I modified the > source, forgot to reload and got the same error again with a wrong line > displayed. Also note that reloading is not so common; usually you just > restart your application and that will give you the right traceback. I know the case when this happens is really unsusual, but the interperter could be able to alert you than that line of the traceback is wrong. > Also I'm not sure the warning you proposed is the best way to handle this. I agree that, another approach is to save a copy of the source file associated to the compiled code (like a .pys). -- ___ Python tracker <http://bugs.python.org/issue8087> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8087] Unupdated source file in traceback
New submission from Diego Mascialino : 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 "", line 1, in 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 "", line 1, in 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 "", line 1, in 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. Maybe "use reload()" might appear. -- components: Interpreter Core messages: 100600 nosy: dmascialino, jjconti severity: normal status: open title: Unupdated source file in traceback type: feature request versions: Python 2.7 ___ Python tracker <http://bugs.python.org/issue8087> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8087] Unupdated source file in traceback
Diego Mascialino added the comment: Martin, I am not talking about a loop checking source file changes. I think the check could be done only when the traceback is printed. The function PyErr_Display() calls PyTracBack_Print() and so on until _Py_DisplaySourceLine() is called. The latter reads the source file and prints the line. I don't know which is the best way to know if the source file was updated. But i think that it's possible to check it there. I think this could apply only when using the interactive console. -- ___ Python tracker <http://bugs.python.org/issue8087> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com