summaryrefslogtreecommitdiff
path: root/Lib/idlelib/run.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/idlelib/run.py')
-rw-r--r--Lib/idlelib/run.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index 96da4593b4..98b8c13030 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -1,5 +1,6 @@
import sys
import os
+import linecache
import time
import socket
import traceback
@@ -17,6 +18,22 @@ import __main__
LOCALHOST = '127.0.0.1'
+try:
+ import warnings
+except ImportError:
+ pass
+else:
+ def idle_formatwarning_subproc(message, category, filename, lineno):
+ """Format warnings the IDLE way"""
+ s = "\nWarning (from warnings module):\n"
+ s += ' File \"%s\", line %s\n' % (filename, lineno)
+ line = linecache.getline(filename, lineno).strip()
+ if line:
+ s += " %s\n" % line
+ s += "%s: %s\n" % (category.__name__, message)
+ return s
+ warnings.formatwarning = idle_formatwarning_subproc
+
# Thread shared globals: Establish a queue between a subthread (which handles
# the socket) and the main thread (which runs user code), plus global
# completion and exit flags: