Issue #9293: I/O streams now raise `io.UnsupportedOperation` when an
unsupported operation is attempted (for example, writing to a file open
only for reading).
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 4f450da..ff278cf 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -417,7 +417,8 @@
 static PyObject *
 err_mode(char *action)
 {
-    PyErr_Format(PyExc_ValueError, "File not open for %s", action);
+    PyErr_Format(IO_STATE->unsupported_operation,
+                 "File not open for %s", action);
     return NULL;
 }