allow more operations to work on detached streams (closes #23093)

Patch by Martin Panter.
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
index 8084aae..02cf038 100644
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -1359,7 +1359,7 @@
 
     nameobj = _PyObject_GetAttrId((PyObject *) self, &PyId_name);
     if (nameobj == NULL) {
-        if (PyErr_ExceptionMatches(PyExc_AttributeError))
+        if (PyErr_ExceptionMatches(PyExc_Exception))
             PyErr_Clear();
         else
             return NULL;