Skip to content

Commit 4f3cd02

Browse files
Address review: handle case where __name__ is not None and not a unicode object
1 parent 4d4371c commit 4f3cd02

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Python/_warnings.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -935,13 +935,15 @@ setup_context(Py_ssize_t stack_level,
935935
if (rc < 0) {
936936
goto handle_error;
937937
}
938-
if (rc == 0) {
939-
*module = PyUnicode_FromString("<string>");
940-
if (*module == NULL)
941-
goto handle_error;
938+
if (rc > 0) {
939+
if (Py_IsNone(*module) || PyUnicode_Check(*module)) {
940+
return 1;
941+
}
942+
Py_DECREF(*module);
942943
}
943-
else {
944-
assert(Py_IsNone(*module) || PyUnicode_Check(*module));
944+
*module = PyUnicode_FromString("<string>");
945+
if (*module == NULL) {
946+
goto handle_error;
945947
}
946948

947949
return 1;

0 commit comments

Comments
 (0)