[Idle-dev] [ idlefork-Patches-869012 ] Update linecache when showing exceptions

SourceForge.net noreply at sourceforge.net
Thu Jan 1 23:00:40 EST 2004


Patches item #869012, was opened at 2004-01-01 18:58
Message generated for change (Comment added) made by kbk
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=309579&aid=869012&group_id=9579

Category: None
Group: None
>Status: Closed
>Resolution: Accepted
Priority: 5
Submitted By: Noam Raphael (noamr)
>Assigned to: Kurt B. Kaiser (kbk)
Summary: Update linecache when showing exceptions

Initial Comment:
When exceptions are shown, the linecache module is
being used. If a file was changed while IDLE was
running, linecache won't know about it and will show
the line from the file in cache, which is very
confusing sometimes, since it may have no relation to
what actually caused the exception.

An example:
>>> file("t.py", "w").write("1/0")
>>> execfile("t.py")
Traceback (most recent call last):
  File "<pyshell#17>", line 1, in -toplevel-
    execfile("t.py")
  File "t.py", line 1, in -toplevel-
    1/0
ZeroDivisionError: integer division or modulo by zero
>>> file("t.py", "w").write("2/0")
>>> execfile("t.py")
Traceback (most recent call last):
  File "<pyshell#19>", line 1, in -toplevel-
    execfile("t.py")
  File "t.py", line 1, in -toplevel-
    1/0               <======== Should have been 2/0!
ZeroDivisionError: integer division or modulo by zero

The solution is to add those two line at the beginning
of function print_exception in run.py (after line 113):
 def print_exception():
+    import linecache
+    linecache.checkcache()
This causes the cache to update itself, and the correct
line is shown.

----------------------------------------------------------------------

>Comment By: Kurt B. Kaiser (kbk)
Date: 2004-01-01 23:00

Message:
Logged In: YES 
user_id=149084

Thanks for the patch!

IDLEfork run.py 1.25
IDLE (python 2.4a0) run.py 1.27

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=309579&aid=869012&group_id=9579



More information about the IDLE-dev mailing list