diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 887591a681b25c..c77cc0bd810e0f 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2864,11 +2864,9 @@ PyAPI_FUNC(void) PySys_AddWarnOptionUnicode(PyObject *option) { PyThreadState *tstate = _PyThreadState_GET(); - if (_PySys_AddWarnOptionWithError(tstate, option) < 0) { + if (tstate && _PySys_AddWarnOptionWithError(tstate, option) < 0) { /* No return value, therefore clear error state if possible */ - if (tstate) { - _PyErr_Clear(tstate); - } + _PyErr_Clear(tstate); } }