mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 17:14:43 +04:00
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:
parent
9a3f2cbb99
commit
86fc829f4d
1 changed files with 4 additions and 3 deletions
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue