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:
helly25 2024-04-25 12:30:43 +00:00
parent 6967f3cb5c
commit 9a3f2cbb99
No known key found for this signature in database
GPG key ID: 95B24A6EAE247816

View file

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