Skip to content

Commit 531722b

Browse files
committed
Prevent a TypeError: 'NoneType' object is not callable when shutil_rmtree is called without an onexc parameter on Python<=3.11
1 parent 52d7324 commit 531722b

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

newsfragments/xxxx.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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`

setuptools/compat/py311.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
from __future__ import annotations
2+
13
import sys
24
import shutil
35

46

5-
def shutil_rmtree(path, ignore_errors=False, onexc=None):
7+
def shutil_rmtree(
8+
path, ignore_errors: bool = False, onexc: shutil._OnExcCallback | None = None
9+
) -> None:
610
if sys.version_info >= (3, 12):
711
return shutil.rmtree(path, ignore_errors, onexc=onexc)
812

913
def _handler(fn, path, excinfo):
10-
return onexc(fn, path, excinfo[1])
14+
return onexc(fn, path, excinfo[1]) if onexc else None
1115

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

0 commit comments

Comments
 (0)