pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/pre-commit/pre-commit/commit/cffabe54be63f0fd05b42ae73842387d07110feb

ref="https://github.githubassets.com/assets/global-d18f184ea1a06a2c.css" /> Address deprecation warning in `shutil.rmtree(onerror=...)` · pre-commit/pre-commit@cffabe5 · GitHub
Skip to content

Commit cffabe5

Browse files
edgarrmondragonasottile
authored andcommitted
Address deprecation warning in shutil.rmtree(onerror=...)
1 parent 51df34e commit cffabe5

2 files changed

Lines changed: 30 additions & 18 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ jobs:
1919
main-linux:
2020
uses: asottile/workflows/.github/workflows/tox.yml@v1.6.0
2121
with:
22-
env: '["py39", "py310", "py311"]'
22+
env: '["py39", "py310", "py311", "py312"]'
2323
os: ubuntu-latest

pre_commit/util.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -202,24 +202,36 @@ def cmd_output_p(
202202
cmd_output_p = cmd_output_b
203203

204204

205-
def rmtree(path: str) -> None:
206-
"""On windows, rmtree fails for readonly dirs."""
207-
def handle_remove_readonly(
208-
func: Callable[..., Any],
209-
path: str,
210-
exc: tuple[type[OSError], OSError, TracebackType],
205+
def _handle_readonly(
206+
func: Callable[[str], object],
207+
path: str,
208+
exc: OSError,
209+
) -> None:
210+
if (
211+
func in (os.rmdir, os.remove, os.unlink) and
212+
exc.errno in {errno.EACCES, errno.EPERM}
213+
):
214+
for p in (path, os.path.dirname(path)):
215+
os.chmod(p, os.stat(p).st_mode | stat.S_IWUSR)
216+
func(path)
217+
else:
218+
raise
219+
220+
221+
if sys.version_info < (3, 12): # pragma: <3.12 cover
222+
def _handle_readonly_old(
223+
func: Callable[[str], object],
224+
path: str,
225+
excinfo: tuple[type[OSError], OSError, TracebackType],
211226
) -> None:
212-
excvalue = exc[1]
213-
if (
214-
func in (os.rmdir, os.remove, os.unlink) and
215-
excvalue.errno in {errno.EACCES, errno.EPERM}
216-
):
217-
for p in (path, os.path.dirname(path)):
218-
os.chmod(p, os.stat(p).st_mode | stat.S_IWUSR)
219-
func(path)
220-
else:
221-
raise
222-
shutil.rmtree(path, ignore_errors=False, onerror=handle_remove_readonly)
227+
return _handle_readonly(func, path, excinfo[1])
228+
229+
def rmtree(path: str) -> None:
230+
shutil.rmtree(path, ignore_errors=False, onerror=_handle_readonly_old)
231+
else: # pragma: >=3.12 cover
232+
def rmtree(path: str) -> None:
233+
"""On windows, rmtree fails for readonly dirs."""
234+
shutil.rmtree(path, ignore_errors=False, onexc=_handle_readonly)
223235

224236

225237
def win_exe(s: str) -> str:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy