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