Kaydet (Commit) 7cb11fa8 authored tarafından Antoine Pitrou's avatar Antoine Pitrou

Close #19379: Lazily import linecache in the warnings module, to make startup…

Close #19379: Lazily import linecache in the warnings module, to make startup with warnings faster until a warning gets printed.
üst f740d467
"""Python part of the warnings subsystem.""" """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 import sys
__all__ = ["warn", "showwarning", "formatwarning", "filterwarnings", __all__ = ["warn", "showwarning", "formatwarning", "filterwarnings",
...@@ -21,6 +17,7 @@ def showwarning(message, category, filename, lineno, file=None, line=None): ...@@ -21,6 +17,7 @@ def showwarning(message, category, filename, lineno, file=None, line=None):
def formatwarning(message, category, filename, lineno, line=None): def formatwarning(message, category, filename, lineno, line=None):
"""Function to format a warning the standard way.""" """Function to format a warning the standard way."""
import linecache
s = "%s:%s: %s: %s\n" % (filename, lineno, category.__name__, message) s = "%s:%s: %s: %s\n" % (filename, lineno, category.__name__, message)
line = linecache.getline(filename, lineno) if line is None else line line = linecache.getline(filename, lineno) if line is None else line
if line: if line:
...@@ -233,6 +230,7 @@ def warn_explicit(message, category, filename, lineno, ...@@ -233,6 +230,7 @@ def warn_explicit(message, category, filename, lineno,
# Prime the linecache for formatting, in case the # Prime the linecache for formatting, in case the
# "file" is actually in a zipfile or something. # "file" is actually in a zipfile or something.
import linecache
linecache.getlines(filename, module_globals) linecache.getlines(filename, module_globals)
if action == "error": if action == "error":
......
...@@ -21,6 +21,9 @@ Core and Builtins ...@@ -21,6 +21,9 @@ Core and Builtins
Library 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 #19327: Fixed the working of regular expressions with too big charset.
- Issue #17400: New 'is_global' attribute for ipaddress to tell if an address - Issue #17400: New 'is_global' attribute for ipaddress to tell if an address
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment