use _typeshed's Path aliases (#4214)

This commit is contained in:
Jelle Zijlstra
2020-06-10 20:57:09 -07:00
committed by GitHub
parent 86f03f2d7b
commit 43e93f803f
42 changed files with 483 additions and 757 deletions

View File

@@ -4,19 +4,13 @@
import os
import sys
from typing import overload, List, Any, AnyStr, Sequence, Tuple, TypeVar, Union, Text, Callable, Optional
from _typeshed import StrPath, BytesPath, AnyPath
if sys.version_info < (3, 8):
_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
@@ -79,26 +73,26 @@ if sys.version_info < (3, 8):
# 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: ...
if sys.version_info >= (3, 3):
def exists(path: Union[_PathType, int]) -> bool: ...
def exists(path: Union[AnyPath, int]) -> bool: ...
else:
def exists(path: _PathType) -> bool: ...
def lexists(path: _PathType) -> bool: ...
def exists(path: AnyPath) -> 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(s: _PathType) -> bool: ...
def ismount(s: _PathType) -> bool: ...
def getsize(filename: AnyPath) -> int: ...
def isabs(s: AnyPath) -> bool: ...
def isfile(path: AnyPath) -> bool: ...
def isdir(s: AnyPath) -> bool: ...
def islink(s: AnyPath) -> bool: ...
def ismount(s: AnyPath) -> bool: ...
if sys.version_info < (3, 0):
# Make sure signatures are disjunct, and allow combinations of bytes and unicode.
@@ -108,23 +102,23 @@ if sys.version_info < (3, 8):
@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, but things seem to behave correctly anyway.
@overload
def join(s: _StrPath, *paths: _StrPath) -> Text: ...
def join(s: StrPath, *paths: StrPath) -> Text: ...
@overload
def join(s: _BytesPath, *paths: _BytesPath) -> bytes: ...
def join(s: BytesPath, *paths: BytesPath) -> bytes: ...
else:
def join(s: AnyStr, *paths: AnyStr) -> AnyStr: ...
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: ...