On 13/07/2026 16:29, Chris Angelico via Python-list wrote:
On Tue, 14 Jul 2026 at 01:18, Rob Cliffe via Python-list
<[email protected]> wrote:
Thanks for your reply, Random.
On 13/07/2026 06:44, Random832 wrote:
On Sun, Jul 12, 2026, at 21:13, Rob Cliffe via Python-list wrote:
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.
First of all, how is it misleading?
It is "arguably misleading" in that it suggests - at least to me - that
the caller does not have the required permissions to delete the file.
Which is likely not the case.
If it's raising an error, then yes, at the moment, the caller does not
have the required permissions to delete the file. If you *do* have
permission to delete the file, even if it's read only, then you won't
get the error. I'm not sure what the conflict is here.
Thanks for your reply, Chris.
I don't think we are at cross-purposes here.
I think you are well aware that if you try to delete a read-only file,
and fail,
when you would succeed if the file were not read-only and everything
else remained the same,
the Exception you currently get is a PermissionError.
In which case it seems to me that you are somewhat splitting hairs.
It seems to me to be useful to distinguish between
cases where the attempt fails because the file is owned by someone else
the case where the attempt only fails because the file is read-only.
We already have a FileExistsError subclass of OSError, which AIUI allows
you to distinguish
between the cases where trying to create an file (say)
fails because the file already exists
fails because you do not have permission to write to the parent
directory.
This distinction is useful information.
In the same way, surely it is useful to have more information
about why trying to delete a file failed.
Maybe you have permission to change the permissions, but that's not
the same thing. You might also have permission to use "sudo", or to
pop up an authentication prompt, or something, but again, that's
outside the scope of a simple error.
The error says, you don't have permission to do that. Which is a fact.
Second, there's no underlying difference in the error reported by the OS, so
all of the same checking logic you describe below would have to be done
internally.
Exactly. And it could be done (by someone more knowledgeable than I) in
a manner independent of the OS or the filing system.
Removing the need to reinvent - and debug - the wheel.
Why though? How often is it fundamentally relevant that the particular
permissions error is "the directory is read-only but owned by you",
and how often is something ELSE relevant instead?
I was talking about a read-only file, not a read-only directory.
That may be another ball game - one I haven't thought about.
(I wasn's suggesting a DirectoryReadOnly Exception, though there might
be some merit in the idea.)
Python is not HQ9+
and does not give you primitives to do the exact thing you personally
happen to want to do; it gives you tools that you can build into
whatever you need.
Of course, you're welcome to submit a PR and wait for a response. Even
if it gets accepted, you then have to wait until the next release to
get it added to the language. Or you could build your own Python from
source with whatever features you feel like adding. I'm sure both of
those options are far easier than, yaknow, just writing the logic you
need.
You jest of course. My point was that such logic may be written not
just by me,
but by many others. Reinventing the wheel.
Best wishes
Rob Cliffe
ChrisA
--
https://mail.python.org/mailman3//lists/python-list.python.org