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
5d3e8002
Commit
5d3e8002
authored
Sep 24, 2017
by
Oren Milman
Committed by
Serhiy Storchaka
Sep 24, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-31566: Fix an assertion failure in _warnings.warn() in case of a bad __name__ global. (#3717)
parent
91fb0afe
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
3 deletions
+16
-3
Lib/test/test_warnings/__init__.py
Lib/test/test_warnings/__init__.py
+10
-0
Misc/NEWS.d/next/Core and Builtins/2017-09-24-09-57-04.bpo-31566.OxwINs.rst
...ore and Builtins/2017-09-24-09-57-04.bpo-31566.OxwINs.rst
+2
-0
Python/_warnings.c
Python/_warnings.c
+4
-3
No files found.
Lib/test/test_warnings/__init__.py
View file @
5d3e8002
...
...
@@ -856,6 +856,16 @@ class _WarningsTests(BaseTest, unittest.TestCase):
self
.
assertRaises
(
TypeError
):
wmod
.
warn_explicit
(
'foo'
,
Warning
,
'bar'
,
1
)
@
support
.
cpython_only
def
test_issue31566
(
self
):
# warn() shouldn't cause an assertion failure in case of a bad
# __name__ global.
with
original_warnings
.
catch_warnings
(
module
=
self
.
module
):
self
.
module
.
filterwarnings
(
'error'
,
category
=
UserWarning
)
with
support
.
swap_item
(
globals
(),
'__name__'
,
b'foo'
),
\
support
.
swap_item
(
globals
(),
'__file__'
,
None
):
self
.
assertRaises
(
UserWarning
,
self
.
module
.
warn
,
'bar'
)
class
WarningsDisplayTests
(
BaseTest
):
...
...
Misc/NEWS.d/next/Core and Builtins/2017-09-24-09-57-04.bpo-31566.OxwINs.rst
0 → 100644
View file @
5d3e8002
Fix an assertion failure in `_warnings.warn()` in case of a bad
``__name__`` global. Patch by Oren Milman.
Python/_warnings.c
View file @
5d3e8002
...
...
@@ -684,13 +684,14 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
/* Setup module. */
*
module
=
PyDict_GetItemString
(
globals
,
"__name__"
);
if
(
*
module
==
NULL
)
{
if
(
*
module
==
Py_None
||
(
*
module
!=
NULL
&&
PyUnicode_Check
(
*
module
)))
{
Py_INCREF
(
*
module
);
}
else
{
*
module
=
PyUnicode_FromString
(
"<string>"
);
if
(
*
module
==
NULL
)
goto
handle_error
;
}
else
Py_INCREF
(
*
module
);
/* Setup filename. */
*
filename
=
PyDict_GetItemString
(
globals
,
"__file__"
);
...
...
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