-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
bpo-31566: Fix an assertion failure in _warnings.warn() in case of a bad __name__ global #3717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-31566: Fix an assertion failure in _warnings.warn() in case of a bad __name__ global #3717
Conversation
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many ways to handle this issue and this way looks the right way to me.
Lib/test/test_warnings/__init__.py
Outdated
| with support.swap_item(globals(), '__name__', b'foo'), \ | ||
| support.swap_item(globals(), '__file__', None), \ | ||
| support.captured_stderr(): | ||
| self.module.warn('bar') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Raise an exception with -Werror.
Python/_warnings.c
Outdated
| /* Setup module. */ | ||
| *module = PyDict_GetItemString(globals, "__name__"); | ||
| if (*module == NULL) { | ||
| if (*module == NULL || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This expression is slightly hard to understand. I would rewrite it as
if (*module == Py_None || (*module != NULL && PyUnicode_Check(*module))) {
Py_INCREF(*module);
}
else {
...
or
if (*module != NULL && (*module == Py_None || PyUnicode_Check(*module))) {
Py_INCREF(*module);
}
else {
...
|
Thanks @orenmn for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.6. |
|
GH-3730 is a backport of this pull request to the 3.6 branch. |
… of a bad __name__ global. (pythonGH-3717) (cherry picked from commit 5d3e800)
|
Thanks @orenmn for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7. |
|
Sorry, @orenmn and @serhiy-storchaka, I could not cleanly backport this to |
_warnings.c: add a check whether__name__isn't a string.test_warnings/__init__.py: add a test to verify that the assertion failure is no more.https://bugs.python.org/issue31566