Skip to content

Commit c78bc57

Browse files
authored
shutil.rmtree: add avoids_symlink_attacks attribute (#9366)
1 parent 9bddd3a commit c78bc57

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

stdlib/shutil.pyi

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import os
22
import sys
33
from _typeshed import BytesPath, StrOrBytesPath, StrPath, SupportsRead, SupportsWrite
44
from collections.abc import Callable, Iterable, Sequence
5-
from typing import Any, AnyStr, NamedTuple, TypeVar, overload
5+
from typing import Any, AnyStr, NamedTuple, Protocol, TypeVar, overload
66
from typing_extensions import TypeAlias
77

88
__all__ = [
@@ -84,13 +84,22 @@ else:
8484

8585
_OnErrorCallback: TypeAlias = Callable[[Callable[..., Any], Any, Any], object]
8686

87-
if sys.version_info >= (3, 11):
88-
def rmtree(
89-
path: StrOrBytesPath, ignore_errors: bool = ..., onerror: _OnErrorCallback | None = ..., *, dir_fd: int | None = ...
90-
) -> None: ...
91-
92-
else:
93-
def rmtree(path: StrOrBytesPath, ignore_errors: bool = ..., onerror: _OnErrorCallback | None = ...) -> None: ...
87+
class _RmtreeType(Protocol):
88+
avoids_symlink_attacks: bool
89+
if sys.version_info >= (3, 11):
90+
def __call__(
91+
self,
92+
path: StrOrBytesPath,
93+
ignore_errors: bool = ...,
94+
onerror: _OnErrorCallback | None = ...,
95+
*,
96+
dir_fd: int | None = ...,
97+
) -> None: ...
98+
99+
else:
100+
def __call__(self, path: StrOrBytesPath, ignore_errors: bool = ..., onerror: _OnErrorCallback | None = ...) -> None: ...
101+
102+
rmtree: _RmtreeType
94103

95104
_CopyFn: TypeAlias = Callable[[str, str], object] | Callable[[StrPath, StrPath], object]
96105

tests/stubtest_allowlists/py3_common.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ poplib.POP3_SSL.stls # bad declaration of inherited function. See poplib.pyi
165165
pyexpat.expat_CAPI
166166
select.poll # Depends on configuration
167167
selectors.DevpollSelector # Depends on configuration
168+
shutil.rmtree # stubtest doesn't like that we have this as an instance of a callback protocol instead of a function
168169
socketserver.BaseServer.RequestHandlerClass # is defined as a property, because we need `Self` type
169170
socketserver.BaseServer.fileno # implemented in derived classes
170171
socketserver.BaseServer.get_request # implemented in derived classes

0 commit comments

Comments
 (0)