1
1
import os
2
2
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
4
4
from collections .abc import Callable , Iterable , Sequence
5
5
from tarfile import _TarfileFilter
6
6
from typing import Any , AnyStr , NamedTuple , NoReturn , Protocol , TypeVar , overload
@@ -36,9 +36,8 @@ __all__ = [
36
36
]
37
37
38
38
_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 )
42
41
43
42
class Error (OSError ): ...
44
43
class SameFileError (Error ): ...
@@ -52,23 +51,23 @@ def copyfile(src: StrOrBytesPath, dst: _StrOrBytesPathT, *, follow_symlinks: boo
52
51
def copymode (src : StrOrBytesPath , dst : StrOrBytesPath , * , follow_symlinks : bool = True ) -> None : ...
53
52
def copystat (src : StrOrBytesPath , dst : StrOrBytesPath , * , follow_symlinks : bool = True ) -> None : ...
54
53
@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 : ...
56
55
@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 : ...
58
57
@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 : ...
60
59
@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 : ...
62
61
def ignore_patterns (* patterns : StrPath ) -> Callable [[Any , list [str ]], set [str ]]: ...
63
62
def copytree (
64
63
src : StrPath ,
65
- dst : StrPath ,
64
+ dst : _StrPathT ,
66
65
symlinks : bool = False ,
67
66
ignore : None | Callable [[str , list [str ]], Iterable [str ]] | Callable [[StrPath , list [str ]], Iterable [str ]] = None ,
68
67
copy_function : Callable [[str , str ], object ] = ...,
69
68
ignore_dangling_symlinks : bool = False ,
70
69
dirs_exist_ok : bool = False ,
71
- ) -> _PathReturn : ...
70
+ ) -> _StrPathT : ...
72
71
73
72
_OnErrorCallback : TypeAlias = Callable [[Callable [..., Any ], str , ExcInfo ], object ]
74
73
_OnExcCallback : TypeAlias = Callable [[Callable [..., Any ], str , BaseException ], object ]
@@ -129,12 +128,7 @@ _CopyFn: TypeAlias = Callable[[str, str], object] | Callable[[StrPath, StrPath],
129
128
# N.B. shutil.move appears to take bytes arguments, however,
130
129
# this does not work when dst is (or is within) an existing directory.
131
130
# (#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 : ...
138
132
139
133
class _ntuple_diskusage (NamedTuple ):
140
134
total : int
0 commit comments