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)):