mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-18 00:24:47 +04:00
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).
This commit is contained in:
parent
6967f3cb5c
commit
9a3f2cbb99
1 changed files with 4 additions and 4 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue