Commit e6b42438 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #23016: A warning no longer produces an AttributeError when sys.stderr

is None.
parent 083f6fba
......@@ -560,6 +560,15 @@ class _WarningsTests(BaseTest):
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(unittest.TestCase):
......
......@@ -26,6 +26,9 @@ def _show_warning(message, category, filename, lineno, file=None, line=None):
"""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 - warnings get lost
return
try:
file.write(formatwarning(message, category, filename, lineno, line))
except IOError:
......
......@@ -13,6 +13,9 @@ Core and Builtins
Library
-------
- Issue #23016: A warning no longer produces an AttributeError when sys.stderr
is None.
- Issue #14099: ZipFile.open() no longer reopen the underlying file. Objects
returned by ZipFile.open() can now operate independently of the ZipFile even
if the ZipFile was created by passing in a file-like object as the first
......
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