Skip to content

Commit 1e43190

Browse files
authored
Exact return types instead of shutil._PathReturn (#13767)
1 parent 1d86d18 commit 1e43190

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

stdlib/shutil.pyi

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import sys
3-
from _typeshed import BytesPath, ExcInfo, FileDescriptorOrPath, StrOrBytesPath, StrPath, SupportsRead, SupportsWrite
3+
from _typeshed import BytesPath, ExcInfo, FileDescriptorOrPath, MaybeNone, StrOrBytesPath, StrPath, SupportsRead, SupportsWrite
44
from collections.abc import Callable, Iterable, Sequence
55
from tarfile import _TarfileFilter
66
from typing import Any, AnyStr, NamedTuple, NoReturn, Protocol, TypeVar, overload
@@ -36,9 +36,8 @@ __all__ = [
3636
]
3737

3838
_StrOrBytesPathT = TypeVar("_StrOrBytesPathT", bound=StrOrBytesPath)
39-
# Return value of some functions that may either return a path-like object that was passed in or
40-
# a string
41-
_PathReturn: TypeAlias = Any
39+
_StrPathT = TypeVar("_StrPathT", bound=StrPath)
40+
_BytesPathT = TypeVar("_BytesPathT", bound=BytesPath)
4241

4342
class Error(OSError): ...
4443
class SameFileError(Error): ...
@@ -52,23 +51,23 @@ def copyfile(src: StrOrBytesPath, dst: _StrOrBytesPathT, *, follow_symlinks: boo
5251
def copymode(src: StrOrBytesPath, dst: StrOrBytesPath, *, follow_symlinks: bool = True) -> None: ...
5352
def copystat(src: StrOrBytesPath, dst: StrOrBytesPath, *, follow_symlinks: bool = True) -> None: ...
5453
@overload
55-
def copy(src: StrPath, dst: StrPath, *, follow_symlinks: bool = True) -> _PathReturn: ...
54+
def copy(src: StrPath, dst: _StrPathT, *, follow_symlinks: bool = True) -> _StrPathT | str: ...
5655
@overload
57-
def copy(src: BytesPath, dst: BytesPath, *, follow_symlinks: bool = True) -> _PathReturn: ...
56+
def copy(src: BytesPath, dst: _BytesPathT, *, follow_symlinks: bool = True) -> _BytesPathT | bytes: ...
5857
@overload
59-
def copy2(src: StrPath, dst: StrPath, *, follow_symlinks: bool = True) -> _PathReturn: ...
58+
def copy2(src: StrPath, dst: _StrPathT, *, follow_symlinks: bool = True) -> _StrPathT | str: ...
6059
@overload
61-
def copy2(src: BytesPath, dst: BytesPath, *, follow_symlinks: bool = True) -> _PathReturn: ...
60+
def copy2(src: BytesPath, dst: _BytesPathT, *, follow_symlinks: bool = True) -> _BytesPathT | bytes: ...
6261
def ignore_patterns(*patterns: StrPath) -> Callable[[Any, list[str]], set[str]]: ...
6362
def copytree(
6463
src: StrPath,
65-
dst: StrPath,
64+
dst: _StrPathT,
6665
symlinks: bool = False,
6766
ignore: None | Callable[[str, list[str]], Iterable[str]] | Callable[[StrPath, list[str]], Iterable[str]] = None,
6867
copy_function: Callable[[str, str], object] = ...,
6968
ignore_dangling_symlinks: bool = False,
7069
dirs_exist_ok: bool = False,
71-
) -> _PathReturn: ...
70+
) -> _StrPathT: ...
7271

7372
_OnErrorCallback: TypeAlias = Callable[[Callable[..., Any], str, ExcInfo], object]
7473
_OnExcCallback: TypeAlias = Callable[[Callable[..., Any], str, BaseException], object]
@@ -129,12 +128,7 @@ _CopyFn: TypeAlias = Callable[[str, str], object] | Callable[[StrPath, StrPath],
129128
# N.B. shutil.move appears to take bytes arguments, however,
130129
# this does not work when dst is (or is within) an existing directory.
131130
# (#6832)
132-
if sys.version_info >= (3, 9):
133-
def move(src: StrPath, dst: StrPath, copy_function: _CopyFn = ...) -> _PathReturn: ...
134-
135-
else:
136-
# See https://bugs.python.org/issue32689
137-
def move(src: str, dst: StrPath, copy_function: _CopyFn = ...) -> _PathReturn: ...
131+
def move(src: StrPath, dst: _StrPathT, copy_function: _CopyFn = ...) -> _StrPathT | str | MaybeNone: ...
138132

139133
class _ntuple_diskusage(NamedTuple):
140134
total: int

0 commit comments

Comments
 (0)