changeset: 93818:0050e770b34c parent: 93815:bf98400daa62 parent: 93817:d04dab84388f user: Serhiy Storchaka date: Wed Dec 10 23:04:47 2014 +0200 files: Lib/test/test_warnings.py Lib/warnings.py Misc/NEWS description: Issue #23016: A warning no longer produces an AttributeError when the program is run with pythonw.exe. diff -r bf98400daa62 -r 0050e770b34c Lib/test/test_warnings.py --- a/Lib/test/test_warnings.py Wed Dec 10 11:05:35 2014 -0500 +++ b/Lib/test/test_warnings.py Wed Dec 10 23:04:47 2014 +0200 @@ -666,6 +666,15 @@ finally: globals_dict['__file__'] = oldfile + def test_stderr_none(self): + rc, stdout, stderr = assert_python_ok("-c", + "import sys; sys.stderr = None; " + "import warnings; warnings.simplefilter('always'); " + "warnings.warn('Warning!')") + self.assertEqual(stdout, b'') + self.assertNotIn(b'Warning!', stderr) + self.assertNotIn(b'Error', stderr) + class WarningsDisplayTests(BaseTest): diff -r bf98400daa62 -r 0050e770b34c Lib/warnings.py --- a/Lib/warnings.py Wed Dec 10 11:05:35 2014 -0500 +++ b/Lib/warnings.py Wed Dec 10 23:04:47 2014 +0200 @@ -11,6 +11,9 @@ """Hook to write a warning to a file; replace if you like.""" if file is None: file = sys.stderr + if file is None: + # sys.stderr is None when ran with pythonw.exe - warnings get lost + return try: file.write(formatwarning(message, category, filename, lineno, line)) except OSError: diff -r bf98400daa62 -r 0050e770b34c Misc/NEWS --- a/Misc/NEWS Wed Dec 10 11:05:35 2014 -0500 +++ b/Misc/NEWS Wed Dec 10 23:04:47 2014 +0200 @@ -194,6 +194,9 @@ Library ------- +- Issue #23016: A warning no longer produces an AttributeError when the program + is run with pythonw.exe. + - Issue #21775: shutil.copytree(): fix crash when copying to VFAT. An exception handler assumed that that OSError objects always have a 'winerror' attribute. That is not the case, so the exception handler itself raised AttributeError