mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 21:46:42 +08:00
PathLike cleanup (#5242)
Copy builtins._PathLike to os.PathLike Use os.PathLike exclusively outside of builtins
This commit is contained in:
@@ -8,7 +8,7 @@ from _typeshed import (
|
||||
OpenBinaryModeWriting,
|
||||
OpenTextMode,
|
||||
)
|
||||
from builtins import OSError, _PathLike
|
||||
from builtins import OSError
|
||||
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper as _TextIOWrapper
|
||||
from posix import listdir as listdir, times_result
|
||||
from subprocess import Popen
|
||||
@@ -28,12 +28,14 @@ from typing import (
|
||||
MutableMapping,
|
||||
NoReturn,
|
||||
Optional,
|
||||
Protocol,
|
||||
Sequence,
|
||||
Set,
|
||||
Tuple,
|
||||
TypeVar,
|
||||
Union,
|
||||
overload,
|
||||
runtime_checkable,
|
||||
)
|
||||
from typing_extensions import Literal
|
||||
|
||||
@@ -46,6 +48,7 @@ if sys.version_info >= (3, 9):
|
||||
_supports_unicode_filenames = path.supports_unicode_filenames
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True)
|
||||
|
||||
# ----- os variables -----
|
||||
|
||||
@@ -301,7 +304,9 @@ class stat_result:
|
||||
st_creator: int
|
||||
st_type: int
|
||||
|
||||
PathLike = _PathLike # See comment in builtins
|
||||
@runtime_checkable
|
||||
class PathLike(Protocol[_AnyStr_co]):
|
||||
def __fspath__(self) -> _AnyStr_co: ...
|
||||
|
||||
_FdOrAnyPath = Union[int, AnyPath]
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import os
|
||||
import sys
|
||||
from _typeshed import AnyPath, BytesPath, StrPath
|
||||
from builtins import _PathLike
|
||||
from genericpath import exists as exists
|
||||
from os import PathLike
|
||||
from typing import Any, AnyStr, Optional, Sequence, Tuple, TypeVar, overload
|
||||
|
||||
_T = TypeVar("_T")
|
||||
@@ -25,43 +25,43 @@ devnull: str
|
||||
# ----- os.path function stubs -----
|
||||
# Overloads are necessary to work around python/mypy#3644.
|
||||
@overload
|
||||
def abspath(path: _PathLike[AnyStr]) -> AnyStr: ...
|
||||
def abspath(path: PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
def abspath(path: AnyStr) -> AnyStr: ...
|
||||
@overload
|
||||
def basename(p: _PathLike[AnyStr]) -> AnyStr: ...
|
||||
def basename(p: PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
def basename(p: AnyStr) -> AnyStr: ...
|
||||
@overload
|
||||
def dirname(p: _PathLike[AnyStr]) -> AnyStr: ...
|
||||
def dirname(p: PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
def dirname(p: AnyStr) -> AnyStr: ...
|
||||
@overload
|
||||
def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ...
|
||||
def expanduser(path: PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
def expanduser(path: AnyStr) -> AnyStr: ...
|
||||
@overload
|
||||
def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ...
|
||||
def expandvars(path: PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
def expandvars(path: AnyStr) -> AnyStr: ...
|
||||
@overload
|
||||
def normcase(s: _PathLike[AnyStr]) -> AnyStr: ...
|
||||
def normcase(s: PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
def normcase(s: AnyStr) -> AnyStr: ...
|
||||
@overload
|
||||
def normpath(path: _PathLike[AnyStr]) -> AnyStr: ...
|
||||
def normpath(path: PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
def normpath(path: AnyStr) -> AnyStr: ...
|
||||
|
||||
if sys.platform == "win32":
|
||||
@overload
|
||||
def realpath(path: _PathLike[AnyStr]) -> AnyStr: ...
|
||||
def realpath(path: PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
def realpath(path: AnyStr) -> AnyStr: ...
|
||||
|
||||
else:
|
||||
@overload
|
||||
def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ...
|
||||
def realpath(filename: PathLike[AnyStr]) -> AnyStr: ...
|
||||
@overload
|
||||
def realpath(filename: AnyStr) -> AnyStr: ...
|
||||
|
||||
@@ -97,15 +97,15 @@ def samefile(f1: AnyPath, f2: AnyPath) -> bool: ...
|
||||
def sameopenfile(fp1: int, fp2: int) -> bool: ...
|
||||
def samestat(s1: os.stat_result, s2: os.stat_result) -> bool: ...
|
||||
@overload
|
||||
def split(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
|
||||
def split(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
|
||||
@overload
|
||||
def split(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
|
||||
@overload
|
||||
def splitdrive(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
|
||||
def splitdrive(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
|
||||
@overload
|
||||
def splitdrive(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
|
||||
@overload
|
||||
def splitext(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
|
||||
def splitext(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ...
|
||||
@overload
|
||||
def splitext(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user