summaryrefslogtreecommitdiff
path: root/Python/_warnings.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/_warnings.c')
-rw-r--r--Python/_warnings.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index f56e92d2c1..4ea9fce47c 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -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__");