mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-20 01:24:42 +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],
|
func: Callable[[str], object],
|
||||||
path: str,
|
path: str,
|
||||||
exc: OSError,
|
exc: OSError,
|
||||||
):
|
) -> object:
|
||||||
if (
|
if (
|
||||||
func in (os.rmdir, os.remove, os.unlink) and
|
func in (os.rmdir, os.remove, os.unlink) and
|
||||||
exc.errno in {errno.EACCES, errno.EPERM}
|
exc.errno in {errno.EACCES, errno.EPERM}
|
||||||
):
|
):
|
||||||
for p in (path, os.path.dirname(path)):
|
for p in (path, os.path.dirname(path)):
|
||||||
os.chmod(p, os.stat(p).st_mode | stat.S_IWUSR)
|
os.chmod(p, os.stat(p).st_mode | stat.S_IWUSR)
|
||||||
func(path)
|
return func(path)
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
@ -223,8 +223,8 @@ if sys.version_info < (3, 12): # pragma: <3.12 cover
|
||||||
func: Callable[[str], object],
|
func: Callable[[str], object],
|
||||||
path: str,
|
path: str,
|
||||||
excinfo: tuple[type[OSError], OSError, TracebackType],
|
excinfo: tuple[type[OSError], OSError, TracebackType],
|
||||||
):
|
) -> None:
|
||||||
return _handle_readonly(func, path, excinfo[1])
|
_handle_readonly(func, path, excinfo[1])
|
||||||
|
|
||||||
def rmtree(path: str) -> None:
|
def rmtree(path: str) -> None:
|
||||||
shutil.rmtree(path, ignore_errors=False, onerror=_handle_readonly_old)
|
shutil.rmtree(path, ignore_errors=False, onerror=_handle_readonly_old)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue