Need to also use an Exception parameter, not an OSError parameter. So we apply a cast for this to work.

This commit is contained in:
helly25 2024-04-25 12:41:51 +00:00
parent 9a3f2cbb99
commit 86fc829f4d
No known key found for this signature in database
GPG key ID: 95B24A6EAE247816

View file

@ -12,6 +12,7 @@ from collections.abc import Generator
from types import TracebackType from types import TracebackType
from typing import Any from typing import Any
from typing import Callable from typing import Callable
from typing import cast
from pre_commit import parse_shebang from pre_commit import parse_shebang
@ -205,11 +206,11 @@ else: # pragma: no cover
def _handle_readonly( def _handle_readonly(
func: Callable[[str], object], func: Callable[[str], object],
path: str, path: str,
exc: OSError, exc: Exception,
) -> object: ) -> object:
if ( if (
func in (os.rmdir, os.remove, os.unlink) and func in (os.rmdir, os.remove, os.unlink) and exc is OSError and
exc.errno in {errno.EACCES, errno.EPERM} cast(OSError, 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)