Issue #21497: faulthandler functions now raise a better error if sys.stderr is
None: RuntimeError("sys.stderr is None") instead of AttributeError("'NoneType'
object has no attribute 'fileno'").
diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c
index fff960f..6a145dc 100644
--- a/Modules/faulthandler.c
+++ b/Modules/faulthandler.c
@@ -144,6 +144,10 @@
             PyErr_SetString(PyExc_RuntimeError, "unable to get sys.stderr");
             return NULL;
         }
+        if (file == Py_None) {
+            PyErr_SetString(PyExc_RuntimeError, "sys.stderr is None");
+            return NULL;
+        }
     }
 
     result = _PyObject_CallMethodId(file, &PyId_fileno, "");