mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 20:54:28 +08:00
use _typeshed's Path aliases (#4214)
This commit is contained in:
@@ -1,23 +1,14 @@
|
||||
# NB: path.pyi and stdlib/2 and stdlib/3 must remain consistent!
|
||||
# Stubs for os.path
|
||||
# Ron Murawski <ron@horizonchess.com>
|
||||
|
||||
import os
|
||||
import sys
|
||||
from typing import overload, List, Any, AnyStr, Sequence, Tuple, TypeVar, Union, Text, Callable, Optional
|
||||
from typing import overload, List, Any, AnyStr, Sequence, Tuple, TypeVar, Text, Callable, Optional
|
||||
from genericpath import exists as exists
|
||||
from _typeshed import StrPath, BytesPath, AnyPath
|
||||
|
||||
_T = TypeVar('_T')
|
||||
|
||||
if sys.version_info >= (3, 6):
|
||||
from builtins import _PathLike
|
||||
_PathType = Union[bytes, Text, _PathLike]
|
||||
_StrPath = Union[Text, _PathLike[Text]]
|
||||
_BytesPath = Union[bytes, _PathLike[bytes]]
|
||||
else:
|
||||
_PathType = Union[bytes, Text]
|
||||
_StrPath = Text
|
||||
_BytesPath = bytes
|
||||
|
||||
# ----- os.path variables -----
|
||||
supports_unicode_filenames: bool
|
||||
@@ -90,31 +81,31 @@ else:
|
||||
def realpath(filename: AnyStr) -> AnyStr: ...
|
||||
|
||||
if sys.version_info >= (3, 6):
|
||||
# In reality it returns str for sequences of _StrPath and bytes for sequences
|
||||
# of _BytesPath, but mypy does not accept such a signature.
|
||||
def commonpath(paths: Sequence[_PathType]) -> Any: ...
|
||||
# In reality it returns str for sequences of StrPath and bytes for sequences
|
||||
# of BytesPath, but mypy does not accept such a signature.
|
||||
def commonpath(paths: Sequence[AnyPath]) -> Any: ...
|
||||
elif sys.version_info >= (3, 5):
|
||||
def commonpath(paths: Sequence[AnyStr]) -> AnyStr: ...
|
||||
|
||||
# NOTE: Empty lists results in '' (str) regardless of contained type.
|
||||
# Also, in Python 2 mixed sequences of Text and bytes results in either Text or bytes
|
||||
# So, fall back to Any
|
||||
def commonprefix(m: Sequence[_PathType]) -> Any: ...
|
||||
def commonprefix(m: Sequence[AnyPath]) -> Any: ...
|
||||
|
||||
def lexists(path: _PathType) -> bool: ...
|
||||
def lexists(path: AnyPath) -> bool: ...
|
||||
|
||||
# These return float if os.stat_float_times() == True,
|
||||
# but int is a subclass of float.
|
||||
def getatime(filename: _PathType) -> float: ...
|
||||
def getmtime(filename: _PathType) -> float: ...
|
||||
def getctime(filename: _PathType) -> float: ...
|
||||
def getatime(filename: AnyPath) -> float: ...
|
||||
def getmtime(filename: AnyPath) -> float: ...
|
||||
def getctime(filename: AnyPath) -> float: ...
|
||||
|
||||
def getsize(filename: _PathType) -> int: ...
|
||||
def isabs(s: _PathType) -> bool: ...
|
||||
def isfile(path: _PathType) -> bool: ...
|
||||
def isdir(s: _PathType) -> bool: ...
|
||||
def islink(path: _PathType) -> bool: ...
|
||||
def ismount(path: _PathType) -> bool: ...
|
||||
def getsize(filename: AnyPath) -> int: ...
|
||||
def isabs(s: AnyPath) -> bool: ...
|
||||
def isfile(path: AnyPath) -> bool: ...
|
||||
def isdir(s: AnyPath) -> bool: ...
|
||||
def islink(path: AnyPath) -> bool: ...
|
||||
def ismount(path: AnyPath) -> bool: ...
|
||||
|
||||
if sys.version_info < (3, 0):
|
||||
# Make sure signatures are disjunct, and allow combinations of bytes and unicode.
|
||||
@@ -124,28 +115,27 @@ if sys.version_info < (3, 0):
|
||||
@overload
|
||||
def join(__p1: bytes, *p: bytes) -> bytes: ...
|
||||
@overload
|
||||
def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: _PathType) -> Text: ...
|
||||
def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: AnyPath) -> Text: ...
|
||||
@overload
|
||||
def join(__p1: bytes, __p2: bytes, __p3: Text, *p: _PathType) -> Text: ...
|
||||
def join(__p1: bytes, __p2: bytes, __p3: Text, *p: AnyPath) -> Text: ...
|
||||
@overload
|
||||
def join(__p1: bytes, __p2: Text, *p: _PathType) -> Text: ...
|
||||
def join(__p1: bytes, __p2: Text, *p: AnyPath) -> Text: ...
|
||||
@overload
|
||||
def join(__p1: Text, *p: _PathType) -> Text: ...
|
||||
def join(__p1: Text, *p: AnyPath) -> Text: ...
|
||||
elif sys.version_info >= (3, 6):
|
||||
# Mypy complains that the signatures overlap (same for relpath below), but things seem to behave correctly anyway.
|
||||
@overload
|
||||
def join(a: _StrPath, *paths: _StrPath) -> Text: ...
|
||||
def join(a: StrPath, *paths: StrPath) -> Text: ...
|
||||
@overload
|
||||
def join(a: _BytesPath, *paths: _BytesPath) -> bytes: ...
|
||||
def join(a: BytesPath, *paths: BytesPath) -> bytes: ...
|
||||
else:
|
||||
def join(a: AnyStr, *paths: AnyStr) -> AnyStr: ...
|
||||
|
||||
@overload
|
||||
def relpath(path: _BytesPath, start: Optional[_BytesPath] = ...) -> bytes: ...
|
||||
def relpath(path: BytesPath, start: Optional[BytesPath] = ...) -> bytes: ...
|
||||
@overload
|
||||
def relpath(path: _StrPath, start: Optional[_StrPath] = ...) -> Text: ...
|
||||
def relpath(path: StrPath, start: Optional[StrPath] = ...) -> Text: ...
|
||||
|
||||
def samefile(f1: _PathType, f2: _PathType) -> bool: ...
|
||||
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: ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user