From 9a3f2cbb993c1062f950df0249b1604bac52534c Mon Sep 17 00:00:00 2001 From: helly25 Date: Thu, 25 Apr 2024 12:30:43 +0000 Subject: [PATCH] One more attempt for util.py The original `_handle_readonly` was flagged as not returning `object` even though the actual shutl.rmtree` does not use a return value. So here we actually follow the requirements as seen by mymy iterally (which the local mymp in venv confirms to be correct). --- pre_commit/util.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pre_commit/util.py b/pre_commit/util.py index 3a794bbb..3a02def4 100644 --- a/pre_commit/util.py +++ b/pre_commit/util.py @@ -206,14 +206,14 @@ def _handle_readonly( func: Callable[[str], object], path: str, exc: OSError, -): +) -> object: if ( func in (os.rmdir, os.remove, os.unlink) and exc.errno in {errno.EACCES, errno.EPERM} ): for p in (path, os.path.dirname(path)): os.chmod(p, os.stat(p).st_mode | stat.S_IWUSR) - func(path) + return func(path) else: raise @@ -223,8 +223,8 @@ if sys.version_info < (3, 12): # pragma: <3.12 cover func: Callable[[str], object], path: str, excinfo: tuple[type[OSError], OSError, TracebackType], - ): - return _handle_readonly(func, path, excinfo[1]) + ) -> None: + _handle_readonly(func, path, excinfo[1]) def rmtree(path: str) -> None: shutil.rmtree(path, ignore_errors=False, onerror=_handle_readonly_old)