Further thoughts:
    I get the impression (though no-one has quite explicitly stated it)
that the developers of Python think it is undesirable for Python to look for further information
than that provided by the OS error code.
Which makes sense.
In which case my suggestion would be better directed to the writers of OS's.
E.g. Windows has an ENOENT error code (file not found) but does not have anything like an EREADONLY code. As far as I know (which is not at all 🙂 - information welcome) it is the same with Unix. Still, if there are any OS's supported by Python which DO have such an error code (I don't know if there are any) it would be nice if Python did provide a FileReadOnly Exception for those OS's.
Best wishes
Rob Cliffe

On 13/07/2026 02:13, Rob Cliffe via Python-list wrote:
The built-in subclasses of OSError (Python 3.13) are
    BlockingIOError
    BrokenPipeError
    ChildProcessError
    ConnectionAbortedError
    ConnectionError
    ConnectionRefusedError
    ConnectionResetError
    EnvironmentError
    FileExistsError
    FileNotFoundError
    IOError
    InterruptedError
    IsADirectoryError
    NotADirectoryError
    PermissionError
    ProcessLookupError
    TimeoutError
    WindowsError
It seems to be that it would be useful to have a FileReadOnly error.
Currently trying to delete a read-only file raises a PermissionError,
which not especially informative, and arguably even misleading.
Of course, code would have to explicitly trap or test for this new error for it to be useful.

This would avoid having to write code such as (wxPython, Windows, simplified from my code):

        try:
            os.remove(filepath)
        except OSError as err:
            errStr = str(err)
            if err.errno == errno.EACCES:
                try:
                    st = os.stat(filepath)
                except Exception:
                    pass
                else:
                    if st.st_mode & 0x92 == 0:
                        errStr = 'File is read-only'
            wx.MessageBox(f"Couldn't delete {filepath}: {errStr}")

Are there any reasons why this could not be implemented, or would be a bad idea?
Best wishes
Rob Cliffe

--
https://mail.python.org/mailman3//lists/python-list.python.org

Reply via email to