(original) (raw)

changeset: 86603:8939c0196990 user: Antoine Pitrou solipsis@pitrou.net date: Thu Oct 24 22:23:42 2013 +0200 files: Lib/warnings.py Misc/NEWS description: Close #19379: Lazily import linecache in the warnings module, to make startup with warnings faster until a warning gets printed. diff -r bffb49efc383 -r 8939c0196990 Lib/warnings.py --- a/Lib/warnings.py Thu Oct 24 23:19:51 2013 +0300 +++ b/Lib/warnings.py Thu Oct 24 22:23:42 2013 +0200 @@ -1,9 +1,5 @@ """Python part of the warnings subsystem.""" -# Note: function level imports should *not* be used -# in this module as it may cause import lock deadlock. -# See bug 683658. -import linecache import sys __all__ = ["warn", "showwarning", "formatwarning", "filterwarnings", @@ -21,6 +17,7 @@ def formatwarning(message, category, filename, lineno, line=None): """Function to format a warning the standard way.""" + import linecache s = "%s:%s: %s: %s\n" % (filename, lineno, category.__name__, message) line = linecache.getline(filename, lineno) if line is None else line if line: @@ -233,6 +230,7 @@ # Prime the linecache for formatting, in case the # "file" is actually in a zipfile or something. + import linecache linecache.getlines(filename, module_globals) if action == "error": diff -r bffb49efc383 -r 8939c0196990 Misc/NEWS --- a/Misc/NEWS Thu Oct 24 23:19:51 2013 +0300 +++ b/Misc/NEWS Thu Oct 24 22:23:42 2013 +0200 @@ -21,6 +21,9 @@ Library ------- +- Issue #19379: Lazily import linecache in the warnings module, to make + startup with warnings faster until a warning gets printed. + - Issue #19327: Fixed the working of regular expressions with too big charset. - Issue #17400: New 'is_global' attribute for ipaddress to tell if an address /solipsis@pitrou.net