Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e6b42438
Commit
e6b42438
authored
Dec 10, 2014
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #23016: A warning no longer produces an AttributeError when sys.stderr
is None.
parent
083f6fba
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
0 deletions
+15
-0
Lib/test/test_warnings.py
Lib/test/test_warnings.py
+9
-0
Lib/warnings.py
Lib/warnings.py
+3
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/test_warnings.py
View file @
e6b42438
...
@@ -560,6 +560,15 @@ class _WarningsTests(BaseTest):
...
@@ -560,6 +560,15 @@ class _WarningsTests(BaseTest):
finally
:
finally
:
globals_dict
[
'__file__'
]
=
oldfile
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
):
class
WarningsDisplayTests
(
unittest
.
TestCase
):
...
...
Lib/warnings.py
View file @
e6b42438
...
@@ -26,6 +26,9 @@ def _show_warning(message, category, filename, lineno, file=None, line=None):
...
@@ -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."""
"""Hook to write a warning to a file; replace if you like."""
if
file
is
None
:
if
file
is
None
:
file
=
sys
.
stderr
file
=
sys
.
stderr
if
file
is
None
:
# sys.stderr is None - warnings get lost
return
try
:
try
:
file
.
write
(
formatwarning
(
message
,
category
,
filename
,
lineno
,
line
))
file
.
write
(
formatwarning
(
message
,
category
,
filename
,
lineno
,
line
))
except
IOError
:
except
IOError
:
...
...
Misc/NEWS
View file @
e6b42438
...
@@ -13,6 +13,9 @@ Core and Builtins
...
@@ -13,6 +13,9 @@ Core and Builtins
Library
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
- Issue #14099: ZipFile.open() no longer reopen the underlying file. Objects
returned by ZipFile.open() can now operate independently of the ZipFile even
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
if the ZipFile was created by passing in a file-like object as the first
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment