From de4c5fdabb706e814977c71ec97416a3f01218ee Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 22 May 2024 12:50:30 -0400 Subject: [PATCH 1/4] Make `shutil.rmtree.onexc` parameter optional --- stdlib/shutil.pyi | 7 ++++++- stubs/setuptools/setuptools/compat/py311.pyi | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/stdlib/shutil.pyi b/stdlib/shutil.pyi index f1f04837df21..80d62891b645 100644 --- a/stdlib/shutil.pyi +++ b/stdlib/shutil.pyi @@ -91,7 +91,12 @@ class _RmtreeType(Protocol): ) -> None: ... @overload def __call__( - self, path: StrOrBytesPath, ignore_errors: bool = False, *, onexc: _OnExcCallback, dir_fd: int | None = None + self, + path: StrOrBytesPath, + ignore_errors: bool = False, + *, + onexc: _OnExcCallback | None = None, + dir_fd: int | None = None, ) -> None: ... elif sys.version_info >= (3, 11): def __call__( diff --git a/stubs/setuptools/setuptools/compat/py311.pyi b/stubs/setuptools/setuptools/compat/py311.pyi index 961f2dbdb8b5..aef113fc9637 100644 --- a/stubs/setuptools/setuptools/compat/py311.pyi +++ b/stubs/setuptools/setuptools/compat/py311.pyi @@ -1,3 +1,4 @@ -from _typeshed import Incomplete, StrOrBytesPath +from _typeshed import StrOrBytesPath +from shutil import _OnExcCallback -def shutil_rmtree(path: StrOrBytesPath, ignore_errors: bool = False, onexc: Incomplete | None = None): ... +def shutil_rmtree(path: StrOrBytesPath, ignore_errors: bool = False, onexc: _OnExcCallback | None = None): ... From df5be2dde77cf519c280d1574cc882c03b130d75 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 22 May 2024 13:07:25 -0400 Subject: [PATCH 2/4] Use BaseException to work with ExcInfo --- stdlib/shutil.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/shutil.pyi b/stdlib/shutil.pyi index 80d62891b645..334bd510ceda 100644 --- a/stdlib/shutil.pyi +++ b/stdlib/shutil.pyi @@ -72,7 +72,7 @@ def copytree( ) -> _PathReturn: ... _OnErrorCallback: TypeAlias = Callable[[Callable[..., Any], str, Any], object] -_OnExcCallback: TypeAlias = Callable[[Callable[..., Any], str, Exception], object] +_OnExcCallback: TypeAlias = Callable[[Callable[..., Any], str, BaseException], object] class _RmtreeType(Protocol): avoids_symlink_attacks: bool From 5a80d788a05f86456848bdafb8beb1c55b3db3f8 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 22 May 2024 13:18:36 -0400 Subject: [PATCH 3/4] Add `ExcInfo` to _OnErrorCallback --- stdlib/shutil.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/shutil.pyi b/stdlib/shutil.pyi index 334bd510ceda..e5fff9c15dd9 100644 --- a/stdlib/shutil.pyi +++ b/stdlib/shutil.pyi @@ -1,6 +1,6 @@ import os import sys -from _typeshed import BytesPath, FileDescriptorOrPath, StrOrBytesPath, StrPath, SupportsRead, SupportsWrite +from _typeshed import BytesPath, ExcInfo, FileDescriptorOrPath, StrOrBytesPath, StrPath, SupportsRead, SupportsWrite from collections.abc import Callable, Iterable, Sequence from tarfile import _TarfileFilter from typing import Any, AnyStr, NamedTuple, Protocol, TypeVar, overload @@ -71,7 +71,7 @@ def copytree( dirs_exist_ok: bool = False, ) -> _PathReturn: ... -_OnErrorCallback: TypeAlias = Callable[[Callable[..., Any], str, Any], object] +_OnErrorCallback: TypeAlias = Callable[[Callable[..., Any], str, ExcInfo], object] _OnExcCallback: TypeAlias = Callable[[Callable[..., Any], str, BaseException], object] class _RmtreeType(Protocol): From d30907691e4a102445216420506984ae67e8493a Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 22 May 2024 14:48:10 -0400 Subject: [PATCH 4/4] Redundant overload --- stdlib/shutil.pyi | 2 -- 1 file changed, 2 deletions(-) diff --git a/stdlib/shutil.pyi b/stdlib/shutil.pyi index e5fff9c15dd9..f6c8a390d85f 100644 --- a/stdlib/shutil.pyi +++ b/stdlib/shutil.pyi @@ -77,8 +77,6 @@ _OnExcCallback: TypeAlias = Callable[[Callable[..., Any], str, BaseException], o class _RmtreeType(Protocol): avoids_symlink_attacks: bool if sys.version_info >= (3, 12): - @overload - def __call__(self, path: StrOrBytesPath, ignore_errors: bool = False, *, dir_fd: int | None = None) -> None: ... @overload @deprecated("The `onerror` parameter is deprecated and will be removed in Python 3.14. Use `onexc` instead.") def __call__(