FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-31566: Fix an assertion failure in _warnings.warn() in case of a bad __name__ global by orenmn · Pull Request #3717 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Next Next commit
init commit
  • Loading branch information
orenmn committed Sep 24, 2017
commit 2c7e223a4ced4849feb1b3209cef1faf61666eba
10 changes: 10 additions & 0 deletions Lib/test/test_warnings/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,16 @@ def test_issue31416(self):
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.
wmod = self.module
with support.swap_item(globals(), '__name__', b'foo'), \
support.swap_item(globals(), '__file__', None), \
support.captured_stderr():
wmod.warn('bar')


class WarningsDisplayTests(BaseTest):

Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix an assertion failure in `_warnings.warn()` in case of a bad
``__name__`` global. Patch by Oren Milman.
2 changes: 1 addition & 1 deletion Python/_warnings.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,

/* Setup module. */
*module = PyDict_GetItemString(globals, "__name__");
if (*module == NULL) {
if (*module == NULL || !PyUnicode_Check(*module)) {
*module = PyUnicode_FromString("<string>");
if (*module == NULL)
goto handle_error;
Expand Down

Back | FazBrowse Home | New Git URL