8000 Normalize tk load failures to ImportErrors. · matplotlib/matplotlib@9cce264 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9cce264

Browse files
committed
Normalize tk load failures to ImportErrors.
Wrapping the internally raised exception should make it easier to debug any failures. Test e.g. by replacing `__file__` by `_file_` in the same source file and recompiling to trigger an AttributeError-that-gets-wrapped-by-ImportError.
1 parent 037fcca commit 9cce264

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)
0