From 0c1ea82b9c822bdae48d69ecc053724b06cfc618 Mon Sep 17 00:00:00 2001 From: helly25 Date: Thu, 25 Apr 2024 12:47:07 +0000 Subject: [PATCH] Need to allow all `OSError` sub-types. --- pre_commit/util.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pre_commit/util.py b/pre_commit/util.py index 7b785d18..1a07783b 100644 --- a/pre_commit/util.py +++ b/pre_commit/util.py @@ -209,7 +209,8 @@ def _handle_readonly( exc: Exception, ) -> object: if ( - func in (os.rmdir, os.remove, os.unlink) and exc is OSError and + func in (os.rmdir, os.remove, os.unlink) and + issubclass(type(exc), OSError) and cast(OSError, exc).errno in {errno.EACCES, errno.EPERM} ): for p in (path, os.path.dirname(path)):