11import os
22import sys
3- from _typeshed import BytesPath , ExcInfo , FileDescriptorOrPath , StrOrBytesPath , StrPath , SupportsRead , SupportsWrite
3+ from _typeshed import BytesPath , ExcInfo , FileDescriptorOrPath , MaybeNone , StrOrBytesPath , StrPath , SupportsRead , SupportsWrite
44from collections .abc import Callable , Iterable , Sequence
55from tarfile import _TarfileFilter
66from 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
4342class Error (OSError ): ...
4443class SameFileError (Error ): ...
@@ -52,23 +51,23 @@ def copyfile(src: StrOrBytesPath, dst: _StrOrBytesPathT, *, follow_symlinks: boo
5251def copymode (src : StrOrBytesPath , dst : StrOrBytesPath , * , follow_symlinks : bool = True ) -> None : ...
5352def 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 : ...
6261def ignore_patterns (* patterns : StrPath ) -> Callable [[Any , list [str ]], set [str ]]: ...
6362def 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
139133class _ntuple_diskusage (NamedTuple ):
140134 total : int
0 commit comments