From: Martin Panter Date: Tue, 5 Apr 2016 06:20:32 +0000 (+0000) Subject: Merge typo fixes from 3.5 X-Git-Tag: v3.6.0a1~271 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c86c91aab02b4ce242b5497256328a880bfdecb4;p=python Merge typo fixes from 3.5 --- c86c91aab02b4ce242b5497256328a880bfdecb4 diff --cc Lib/warnings.py index 1ece5149f4,dfa13ee3fc..f4c8cdc492 --- a/Lib/warnings.py +++ b/Lib/warnings.py @@@ -22,32 -12,24 +22,32 @@@ def _showwarnmsg_impl(msg) if file is None: file = sys.stderr if file is None: - # sys.stderr is None when run with pythonw.exe - warnings get lost + # sys.stderr is None when run with pythonw.exe: + # warnings get lost return + text = _formatwarnmsg(msg) try: - file.write(formatwarning(message, category, filename, lineno, line)) + file.write(text) except OSError: - pass # the file (probably stderr) is invalid - this warning gets lost. + # the file (probably stderr) is invalid - this warning gets lost. + pass -def formatwarning(message, category, filename, lineno, line=None): - """Function to format a warning the standard way.""" - s = "%s:%s: %s: %s\n" % (filename, lineno, category.__name__, message) - if line is None: +def _formatwarnmsg_impl(msg): + s = ("%s:%s: %s: %s\n" + % (msg.filename, msg.lineno, msg.category.__name__, + msg.message)) + + if msg.line is None: try: import linecache - line = linecache.getline(filename, lineno) + line = linecache.getline(msg.filename, msg.lineno) except Exception: # When a warning is logged during Python shutdown, linecache - # and the improt machinery don't work anymore + # and the import machinery don't work anymore line = None + linecache = None + else: + line = msg.line if line: line = line.strip() s += " %s\n" % line