Skip to content

Commit ecce9ae

Browse files
authored
Merge pull request matplotlib#23089 from anntzer/tkie
Normalize tk load failures to ImportErrors.
2 parents dd434d6 + 9cce264 commit ecce9ae

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/_tkagg.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,16 +341,22 @@ static PyModuleDef _tkagg_module = {
341341
PyMODINIT_FUNC PyInit__tkagg(void)
342342
{
343343
load_tkinter_funcs();
344-
if (PyErr_Occurred()) {
344+
PyObject *type, *value, *traceback;
345+
PyErr_Fetch(&type, &value, &traceback);
346+
// Always raise ImportError (normalizing a previously set exception if
347+
// needed) to interact properly with backend auto-fallback.
348+
if (value) {
349+
PyErr_NormalizeException(&type, &value, &traceback);
350+
PyErr_SetObject(PyExc_ImportError, value);
345351
return NULL;
346352
} else if (!TCL_SETVAR) {
347-
PyErr_SetString(PyExc_RuntimeError, "Failed to load Tcl_SetVar");
353+
PyErr_SetString(PyExc_ImportError, "Failed to load Tcl_SetVar");
348354
return NULL;
349355
} else if (!TK_FIND_PHOTO) {
350-
PyErr_SetString(PyExc_RuntimeError, "Failed to load Tk_FindPhoto");
356+
PyErr_SetString(PyExc_ImportError, "Failed to load Tk_FindPhoto");
351357
return NULL;
352358
} else if (!TK_PHOTO_PUT_BLOCK) {
353-
PyErr_SetString(PyExc_RuntimeError, "Failed to load Tk_PhotoPutBlock");
359+
PyErr_SetString(PyExc_ImportError, "Failed to load Tk_PhotoPutBlock");
354360
return NULL;
355361
}
356362
return PyModule_Create(&_tkagg_module);

0 commit comments

Comments
 (0)