Skip to content

Commit

Permalink
Prevent a TypeError: 'NoneType' object is not callable when ``shu…
Browse files Browse the repository at this point in the history
…til_rmtree`` is called without an ``onexc`` parameter on Python<=3.11
  • Loading branch information
Avasam committed May 22, 2024
1 parent 52d7324 commit 531722b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions newsfragments/xxxx.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent a ``TypeError: 'NoneType' object is not callable`` when ``shutil_rmtree`` is called without an ``onexc`` parameter on Python<=3.11 -- by :user:`Avasam`
8 changes: 6 additions & 2 deletions setuptools/compat/py311.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from __future__ import annotations

import sys
import shutil


def shutil_rmtree(path, ignore_errors=False, onexc=None):
def shutil_rmtree(
path, ignore_errors: bool = False, onexc: shutil._OnExcCallback | None = None
) -> None:
if sys.version_info >= (3, 12):
return shutil.rmtree(path, ignore_errors, onexc=onexc)

def _handler(fn, path, excinfo):
return onexc(fn, path, excinfo[1])
return onexc(fn, path, excinfo[1]) if onexc else None

return shutil.rmtree(path, ignore_errors, onerror=_handler)

0 comments on commit 531722b

Please sign in to comment.