Skip to content

Make shutil.rmtree.onexc parameter optional #12002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions stdlib/shutil.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -71,14 +71,12 @@ def copytree(
dirs_exist_ok: bool = False,
) -> _PathReturn: ...

_OnErrorCallback: TypeAlias = Callable[[Callable[..., Any], str, Any], object]
_OnExcCallback: TypeAlias = Callable[[Callable[..., Any], str, Exception], object]
_OnErrorCallback: TypeAlias = Callable[[Callable[..., Any], str, ExcInfo], object]
_OnExcCallback: TypeAlias = Callable[[Callable[..., Any], str, BaseException], object]

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__(
Expand All @@ -91,7 +89,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: ...
Comment on lines 90 to 98
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we need this and the first overload. The first overload seems redundant.

Copy link
Collaborator Author

@Avasam Avasam May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, given the params are kw only and optional. Good catch!

elif sys.version_info >= (3, 11):
def __call__(
Expand Down
5 changes: 3 additions & 2 deletions stubs/setuptools/setuptools/compat/py311.pyi
Original file line number Diff line number Diff line change
@@ -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): ...