Skip to content

Conversation

@orenmn
Copy link
Contributor

@orenmn orenmn commented Sep 24, 2017

  • in _warnings.c: add a check whether __name__ isn't a string.
  • in test_warnings/__init__.py: add a test to verify that the assertion failure is no more.

https://bugs.python.org/issue31566

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a 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.

with support.swap_item(globals(), '__name__', b'foo'), \
support.swap_item(globals(), '__file__', None), \
support.captured_stderr():
self.module.warn('bar')
Copy link
Member

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.

/* Setup module. */
*module = PyDict_GetItemString(globals, "__name__");
if (*module == NULL) {
if (*module == NULL ||
Copy link
Member

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 {
    ...

@serhiy-storchaka serhiy-storchaka merged commit 5d3e800 into python:master Sep 24, 2017
@miss-islington
Copy link
Contributor

Thanks @orenmn for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.6.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-3730 is a backport of this pull request to the 3.6 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 24, 2017
serhiy-storchaka pushed a commit that referenced this pull request Sep 24, 2017
… of a bad __name__ global. (GH-3717) (#3730)

(cherry picked from commit 5d3e800)
@miss-islington
Copy link
Contributor

Thanks @orenmn for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @orenmn and @serhiy-storchaka, I could not cleanly backport this to 2.7 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 5d3e80021ab33360191eb0fbff34e0246c913884 2.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants