Skip to content

Commit 58a4c08

Browse files
authored
shutil.which cannot return PathLike, and fails with cmd: PathLike on Windows Python < 3.12 (#13580)
1 parent 94be358 commit 58a4c08

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

stdlib/shutil.pyi

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import sys
33
from _typeshed import BytesPath, ExcInfo, FileDescriptorOrPath, StrOrBytesPath, StrPath, SupportsRead, SupportsWrite
44
from collections.abc import Callable, Iterable, Sequence
55
from tarfile import _TarfileFilter
6-
from typing import Any, AnyStr, NamedTuple, Protocol, TypeVar, overload
6+
from typing import Any, AnyStr, NamedTuple, NoReturn, Protocol, TypeVar, overload
77
from typing_extensions import TypeAlias, deprecated
88

99
__all__ = [
@@ -36,7 +36,6 @@ __all__ = [
3636
]
3737

3838
_StrOrBytesPathT = TypeVar("_StrOrBytesPathT", bound=StrOrBytesPath)
39-
_StrPathT = TypeVar("_StrPathT", bound=StrPath)
4039
# Return value of some functions that may either return a path-like object that was passed in or
4140
# a string
4241
_PathReturn: TypeAlias = Any
@@ -185,8 +184,13 @@ else:
185184
@overload
186185
def chown(path: FileDescriptorOrPath, user: str | int, group: str | int) -> None: ...
187186

187+
if sys.platform == "win32" and sys.version_info < (3, 12):
188+
@overload
189+
@deprecated("On Windows before Python 3.12, using a PathLike as `cmd` would always fail or return `None`.")
190+
def which(cmd: os.PathLike[str], mode: int = 1, path: StrPath | None = None) -> NoReturn: ...
191+
188192
@overload
189-
def which(cmd: _StrPathT, mode: int = 1, path: StrPath | None = None) -> str | _StrPathT | None: ...
193+
def which(cmd: StrPath, mode: int = 1, path: StrPath | None = None) -> str | None: ...
190194
@overload
191195
def which(cmd: bytes, mode: int = 1, path: StrPath | None = None) -> bytes | None: ...
192196
def make_archive(

0 commit comments

Comments
 (0)