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
252033d5
Commit
252033d5
authored
Sep 11, 2017
by
Oren Milman
Committed by
Serhiy Storchaka
Sep 11, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-31411: Prevent raising a SystemError in case warnings.onceregistry is not a dictionary. (#3485)
parent
3866d9bb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
1 deletion
+20
-1
Lib/test/test_warnings/__init__.py
Lib/test/test_warnings/__init__.py
+11
-0
Misc/NEWS.d/next/Core and Builtins/2017-09-11-08-50-41.bpo-31411.HZz82I.rst
...ore and Builtins/2017-09-11-08-50-41.bpo-31411.HZz82I.rst
+2
-0
Python/_warnings.c
Python/_warnings.c
+7
-1
No files found.
Lib/test/test_warnings/__init__.py
View file @
252033d5
...
...
@@ -794,6 +794,17 @@ class _WarningsTests(BaseTest, unittest.TestCase):
self
.
assertNotIn
(
b'Warning!'
,
stderr
)
self
.
assertNotIn
(
b'Error'
,
stderr
)
@
support
.
cpython_only
def
test_issue31411
(
self
):
# warn_explicit() shouldn't raise a SystemError in case
# warnings.onceregistry isn't a dictionary.
wmod
=
self
.
module
with
original_warnings
.
catch_warnings
(
module
=
wmod
):
wmod
.
filterwarnings
(
'once'
)
with
support
.
swap_attr
(
wmod
,
'onceregistry'
,
None
):
with
self
.
assertRaises
(
TypeError
):
wmod
.
warn_explicit
(
'foo'
,
Warning
,
'bar'
,
1
,
registry
=
None
)
class
WarningsDisplayTests
(
BaseTest
):
...
...
Misc/NEWS.d/next/Core and Builtins/2017-09-11-08-50-41.bpo-31411.HZz82I.rst
0 → 100644
View file @
252033d5
Raise a TypeError instead of SystemError in case warnings.onceregistry is
not a dictionary. Patch by Oren Milman.
Python/_warnings.c
View file @
252033d5
...
...
@@ -86,6 +86,12 @@ get_once_registry(void)
return
NULL
;
return
_PyRuntime
.
warnings
.
once_registry
;
}
if
(
!
PyDict_Check
(
registry
))
{
PyErr_SetString
(
PyExc_TypeError
,
"warnings.onceregistry must be a dict"
);
Py_DECREF
(
registry
);
return
NULL
;
}
Py_DECREF
(
_PyRuntime
.
warnings
.
once_registry
);
_PyRuntime
.
warnings
.
once_registry
=
registry
;
return
registry
;
...
...
@@ -437,7 +443,7 @@ warn_explicit(PyObject *category, PyObject *message,
Py_RETURN_NONE
;
if
(
registry
&&
!
PyDict_Check
(
registry
)
&&
(
registry
!=
Py_None
))
{
PyErr_SetString
(
PyExc_TypeError
,
"'registry' must be a dict"
);
PyErr_SetString
(
PyExc_TypeError
,
"'registry' must be a dict
or None
"
);
return
NULL
;
}
...
...
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