diff --git a/stdlib/2/macpath.pyi b/stdlib/2/macpath.pyi deleted file mode 100644 index fc5c173ef..000000000 --- a/stdlib/2/macpath.pyi +++ /dev/null @@ -1,37 +0,0 @@ -# NB: os2emxpath.pyi, posixpath.pyi, ntpath.pyi, and macpath.pyi must remain consistent! -from typing import Any -from genericpath import * # noqa: F403 - -curdir = ... # type: Any -pardir = ... # type: Any -extsep = ... # type: Any -sep = ... # type: Any -pathsep = ... # type: Any -defpath = ... # type: Any -altsep = ... # type: Any -devnull = ... # type: Any - -def normcase(s): ... -def isabs(s): ... -def join(a, *p): ... -def split(p): ... -def splitext(p): ... -def splitdrive(p): ... -def basename(p): ... -def dirname(p): ... -def islink(path): ... -def lexists(path): ... -def samefile(f1, f2): ... -def sameopenfile(fp1, fp2): ... -def samestat(s1, s2): ... -def ismount(path): ... -def walk(top, func, arg): ... -def expanduser(path): ... -def expandvars(path): ... -def normpath(path): ... -def abspath(path): ... -def realpath(filename): ... - -supports_unicode_filenames = ... # type: Any - -def relpath(path, start=...): ... diff --git a/stdlib/2/ntpath.pyi b/stdlib/2/ntpath.pyi deleted file mode 100644 index fc5c173ef..000000000 --- a/stdlib/2/ntpath.pyi +++ /dev/null @@ -1,37 +0,0 @@ -# NB: os2emxpath.pyi, posixpath.pyi, ntpath.pyi, and macpath.pyi must remain consistent! -from typing import Any -from genericpath import * # noqa: F403 - -curdir = ... # type: Any -pardir = ... # type: Any -extsep = ... # type: Any -sep = ... # type: Any -pathsep = ... # type: Any -defpath = ... # type: Any -altsep = ... # type: Any -devnull = ... # type: Any - -def normcase(s): ... -def isabs(s): ... -def join(a, *p): ... -def split(p): ... -def splitext(p): ... -def splitdrive(p): ... -def basename(p): ... -def dirname(p): ... -def islink(path): ... -def lexists(path): ... -def samefile(f1, f2): ... -def sameopenfile(fp1, fp2): ... -def samestat(s1, s2): ... -def ismount(path): ... -def walk(top, func, arg): ... -def expanduser(path): ... -def expandvars(path): ... -def normpath(path): ... -def abspath(path): ... -def realpath(filename): ... - -supports_unicode_filenames = ... # type: Any - -def relpath(path, start=...): ... diff --git a/stdlib/2/os2emxpath.pyi b/stdlib/2/os2emxpath.pyi index fc5c173ef..09663afa4 100644 --- a/stdlib/2/os2emxpath.pyi +++ b/stdlib/2/os2emxpath.pyi @@ -1,37 +1,177 @@ -# NB: os2emxpath.pyi, posixpath.pyi, ntpath.pyi, and macpath.pyi must remain consistent! -from typing import Any -from genericpath import * # noqa: F403 +# NB: path.pyi and stdlib/2 and stdlib/3 must remain consistent! +# Stubs for os.path +# Ron Murawski -curdir = ... # type: Any -pardir = ... # type: Any -extsep = ... # type: Any -sep = ... # type: Any -pathsep = ... # type: Any -defpath = ... # type: Any -altsep = ... # type: Any -devnull = ... # type: Any +import os +import sys +from typing import ( + overload, List, Any, AnyStr, Sequence, Tuple, BinaryIO, TextIO, + TypeVar, Union, Text, Callable, Optional +) -def normcase(s): ... -def isabs(s): ... -def join(a, *p): ... -def split(p): ... -def splitext(p): ... -def splitdrive(p): ... -def basename(p): ... -def dirname(p): ... -def islink(path): ... -def lexists(path): ... -def samefile(f1, f2): ... -def sameopenfile(fp1, fp2): ... -def samestat(s1, s2): ... -def ismount(path): ... -def walk(top, func, arg): ... -def expanduser(path): ... -def expandvars(path): ... -def normpath(path): ... -def abspath(path): ... -def realpath(filename): ... +_T = TypeVar('_T') -supports_unicode_filenames = ... # type: Any +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 -def relpath(path, start=...): ... +# ----- os.path variables ----- +supports_unicode_filenames: bool +# aliases (also in os) +curdir: str +pardir: str +sep: str +altsep: str +extsep: str +pathsep: str +defpath: str +devnull: str + +# ----- os.path function stubs ----- +if sys.version_info >= (3, 6): + # Overloads are necessary to work around python/mypy#3644. + @overload + def abspath(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def abspath(path: AnyStr) -> AnyStr: ... + @overload + def basename(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def basename(path: AnyStr) -> AnyStr: ... + @overload + def dirname(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def dirname(path: AnyStr) -> AnyStr: ... + @overload + def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def expanduser(path: AnyStr) -> AnyStr: ... + @overload + def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def expandvars(path: AnyStr) -> AnyStr: ... + @overload + def normcase(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def normcase(path: AnyStr) -> AnyStr: ... + @overload + def normpath(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def normpath(path: AnyStr) -> AnyStr: ... + if sys.platform == 'win32': + @overload + def realpath(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def realpath(path: AnyStr) -> AnyStr: ... + else: + @overload + def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def realpath(filename: AnyStr) -> AnyStr: ... + +else: + def abspath(path: AnyStr) -> AnyStr: ... + def basename(path: AnyStr) -> AnyStr: ... + def dirname(path: AnyStr) -> AnyStr: ... + def expanduser(path: AnyStr) -> AnyStr: ... + def expandvars(path: AnyStr) -> AnyStr: ... + def normcase(path: AnyStr) -> AnyStr: ... + def normpath(path: AnyStr) -> AnyStr: ... + if sys.platform == 'win32': + def realpath(path: AnyStr) -> AnyStr: ... + 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: ... +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(list: Sequence[_PathType]) -> Any: ... + +if sys.version_info >= (3, 3): + def exists(path: Union[_PathType, int]) -> bool: ... +else: + def exists(path: _PathType) -> bool: ... +def lexists(path: _PathType) -> bool: ... + +# These return float if os.stat_float_times() == True, +# but int is a subclass of float. +def getatime(path: _PathType) -> float: ... +def getmtime(path: _PathType) -> float: ... +def getctime(path: _PathType) -> float: ... + +def getsize(path: _PathType) -> int: ... +def isabs(path: _PathType) -> bool: ... +def isfile(path: _PathType) -> bool: ... +def isdir(path: _PathType) -> bool: ... +def islink(path: _PathType) -> bool: ... +def ismount(path: _PathType) -> bool: ... + +if sys.version_info < (3, 0): + # Make sure signatures are disjunct, and allow combinations of bytes and unicode. + # (Since Python 2 allows that, too) + # Note that e.g. os.path.join("a", "b", "c", "d", u"e") will still result in + # a type error. + @overload + def join(__p1: bytes, *p: bytes) -> bytes: ... + @overload + def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: _PathType) -> Text: ... + @overload + def join(__p1: bytes, __p2: bytes, __p3: Text, *p: _PathType) -> Text: ... + @overload + def join(__p1: bytes, __p2: Text, *p: _PathType) -> Text: ... + @overload + def join(__p1: Text, *p: _PathType) -> 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(path: _StrPath, *paths: _StrPath) -> Text: ... + @overload + def join(path: _BytesPath, *paths: _BytesPath) -> bytes: ... +else: + def join(path: AnyStr, *paths: AnyStr) -> AnyStr: ... + +@overload +def relpath(path: _BytesPath, start: Optional[_BytesPath] = ...) -> bytes: ... +@overload +def relpath(path: _StrPath, start: Optional[_StrPath] = ...) -> Text: ... + +def samefile(path1: _PathType, path2: _PathType) -> bool: ... +def sameopenfile(fp1: int, fp2: int) -> bool: ... +def samestat(stat1: os.stat_result, stat2: os.stat_result) -> bool: ... + +if sys.version_info >= (3, 6): + @overload + def split(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + @overload + def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitdrive(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitext(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... +else: + def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + +if sys.platform == 'win32': + def splitunc(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # deprecated + +if sys.version_info < (3,): + def walk(path: AnyStr, visit: Callable[[_T, AnyStr, List[AnyStr]], Any], arg: _T) -> None: ... diff --git a/stdlib/2/posixpath.pyi b/stdlib/2/posixpath.pyi deleted file mode 100644 index fc5c173ef..000000000 --- a/stdlib/2/posixpath.pyi +++ /dev/null @@ -1,37 +0,0 @@ -# NB: os2emxpath.pyi, posixpath.pyi, ntpath.pyi, and macpath.pyi must remain consistent! -from typing import Any -from genericpath import * # noqa: F403 - -curdir = ... # type: Any -pardir = ... # type: Any -extsep = ... # type: Any -sep = ... # type: Any -pathsep = ... # type: Any -defpath = ... # type: Any -altsep = ... # type: Any -devnull = ... # type: Any - -def normcase(s): ... -def isabs(s): ... -def join(a, *p): ... -def split(p): ... -def splitext(p): ... -def splitdrive(p): ... -def basename(p): ... -def dirname(p): ... -def islink(path): ... -def lexists(path): ... -def samefile(f1, f2): ... -def sameopenfile(fp1, fp2): ... -def samestat(s1, s2): ... -def ismount(path): ... -def walk(top, func, arg): ... -def expanduser(path): ... -def expandvars(path): ... -def normpath(path): ... -def abspath(path): ... -def realpath(filename): ... - -supports_unicode_filenames = ... # type: Any - -def relpath(path, start=...): ... diff --git a/stdlib/2and3/macpath.pyi b/stdlib/2and3/macpath.pyi new file mode 100644 index 000000000..09663afa4 --- /dev/null +++ b/stdlib/2and3/macpath.pyi @@ -0,0 +1,177 @@ +# NB: path.pyi and stdlib/2 and stdlib/3 must remain consistent! +# Stubs for os.path +# Ron Murawski + +import os +import sys +from typing import ( + overload, List, Any, AnyStr, Sequence, Tuple, BinaryIO, TextIO, + TypeVar, Union, Text, Callable, Optional +) + +_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 +# aliases (also in os) +curdir: str +pardir: str +sep: str +altsep: str +extsep: str +pathsep: str +defpath: str +devnull: str + +# ----- os.path function stubs ----- +if sys.version_info >= (3, 6): + # Overloads are necessary to work around python/mypy#3644. + @overload + def abspath(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def abspath(path: AnyStr) -> AnyStr: ... + @overload + def basename(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def basename(path: AnyStr) -> AnyStr: ... + @overload + def dirname(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def dirname(path: AnyStr) -> AnyStr: ... + @overload + def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def expanduser(path: AnyStr) -> AnyStr: ... + @overload + def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def expandvars(path: AnyStr) -> AnyStr: ... + @overload + def normcase(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def normcase(path: AnyStr) -> AnyStr: ... + @overload + def normpath(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def normpath(path: AnyStr) -> AnyStr: ... + if sys.platform == 'win32': + @overload + def realpath(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def realpath(path: AnyStr) -> AnyStr: ... + else: + @overload + def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def realpath(filename: AnyStr) -> AnyStr: ... + +else: + def abspath(path: AnyStr) -> AnyStr: ... + def basename(path: AnyStr) -> AnyStr: ... + def dirname(path: AnyStr) -> AnyStr: ... + def expanduser(path: AnyStr) -> AnyStr: ... + def expandvars(path: AnyStr) -> AnyStr: ... + def normcase(path: AnyStr) -> AnyStr: ... + def normpath(path: AnyStr) -> AnyStr: ... + if sys.platform == 'win32': + def realpath(path: AnyStr) -> AnyStr: ... + 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: ... +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(list: Sequence[_PathType]) -> Any: ... + +if sys.version_info >= (3, 3): + def exists(path: Union[_PathType, int]) -> bool: ... +else: + def exists(path: _PathType) -> bool: ... +def lexists(path: _PathType) -> bool: ... + +# These return float if os.stat_float_times() == True, +# but int is a subclass of float. +def getatime(path: _PathType) -> float: ... +def getmtime(path: _PathType) -> float: ... +def getctime(path: _PathType) -> float: ... + +def getsize(path: _PathType) -> int: ... +def isabs(path: _PathType) -> bool: ... +def isfile(path: _PathType) -> bool: ... +def isdir(path: _PathType) -> bool: ... +def islink(path: _PathType) -> bool: ... +def ismount(path: _PathType) -> bool: ... + +if sys.version_info < (3, 0): + # Make sure signatures are disjunct, and allow combinations of bytes and unicode. + # (Since Python 2 allows that, too) + # Note that e.g. os.path.join("a", "b", "c", "d", u"e") will still result in + # a type error. + @overload + def join(__p1: bytes, *p: bytes) -> bytes: ... + @overload + def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: _PathType) -> Text: ... + @overload + def join(__p1: bytes, __p2: bytes, __p3: Text, *p: _PathType) -> Text: ... + @overload + def join(__p1: bytes, __p2: Text, *p: _PathType) -> Text: ... + @overload + def join(__p1: Text, *p: _PathType) -> 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(path: _StrPath, *paths: _StrPath) -> Text: ... + @overload + def join(path: _BytesPath, *paths: _BytesPath) -> bytes: ... +else: + def join(path: AnyStr, *paths: AnyStr) -> AnyStr: ... + +@overload +def relpath(path: _BytesPath, start: Optional[_BytesPath] = ...) -> bytes: ... +@overload +def relpath(path: _StrPath, start: Optional[_StrPath] = ...) -> Text: ... + +def samefile(path1: _PathType, path2: _PathType) -> bool: ... +def sameopenfile(fp1: int, fp2: int) -> bool: ... +def samestat(stat1: os.stat_result, stat2: os.stat_result) -> bool: ... + +if sys.version_info >= (3, 6): + @overload + def split(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + @overload + def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitdrive(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitext(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... +else: + def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + +if sys.platform == 'win32': + def splitunc(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # deprecated + +if sys.version_info < (3,): + def walk(path: AnyStr, visit: Callable[[_T, AnyStr, List[AnyStr]], Any], arg: _T) -> None: ... diff --git a/stdlib/2and3/ntpath.pyi b/stdlib/2and3/ntpath.pyi new file mode 100644 index 000000000..09663afa4 --- /dev/null +++ b/stdlib/2and3/ntpath.pyi @@ -0,0 +1,177 @@ +# NB: path.pyi and stdlib/2 and stdlib/3 must remain consistent! +# Stubs for os.path +# Ron Murawski + +import os +import sys +from typing import ( + overload, List, Any, AnyStr, Sequence, Tuple, BinaryIO, TextIO, + TypeVar, Union, Text, Callable, Optional +) + +_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 +# aliases (also in os) +curdir: str +pardir: str +sep: str +altsep: str +extsep: str +pathsep: str +defpath: str +devnull: str + +# ----- os.path function stubs ----- +if sys.version_info >= (3, 6): + # Overloads are necessary to work around python/mypy#3644. + @overload + def abspath(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def abspath(path: AnyStr) -> AnyStr: ... + @overload + def basename(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def basename(path: AnyStr) -> AnyStr: ... + @overload + def dirname(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def dirname(path: AnyStr) -> AnyStr: ... + @overload + def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def expanduser(path: AnyStr) -> AnyStr: ... + @overload + def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def expandvars(path: AnyStr) -> AnyStr: ... + @overload + def normcase(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def normcase(path: AnyStr) -> AnyStr: ... + @overload + def normpath(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def normpath(path: AnyStr) -> AnyStr: ... + if sys.platform == 'win32': + @overload + def realpath(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def realpath(path: AnyStr) -> AnyStr: ... + else: + @overload + def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def realpath(filename: AnyStr) -> AnyStr: ... + +else: + def abspath(path: AnyStr) -> AnyStr: ... + def basename(path: AnyStr) -> AnyStr: ... + def dirname(path: AnyStr) -> AnyStr: ... + def expanduser(path: AnyStr) -> AnyStr: ... + def expandvars(path: AnyStr) -> AnyStr: ... + def normcase(path: AnyStr) -> AnyStr: ... + def normpath(path: AnyStr) -> AnyStr: ... + if sys.platform == 'win32': + def realpath(path: AnyStr) -> AnyStr: ... + 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: ... +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(list: Sequence[_PathType]) -> Any: ... + +if sys.version_info >= (3, 3): + def exists(path: Union[_PathType, int]) -> bool: ... +else: + def exists(path: _PathType) -> bool: ... +def lexists(path: _PathType) -> bool: ... + +# These return float if os.stat_float_times() == True, +# but int is a subclass of float. +def getatime(path: _PathType) -> float: ... +def getmtime(path: _PathType) -> float: ... +def getctime(path: _PathType) -> float: ... + +def getsize(path: _PathType) -> int: ... +def isabs(path: _PathType) -> bool: ... +def isfile(path: _PathType) -> bool: ... +def isdir(path: _PathType) -> bool: ... +def islink(path: _PathType) -> bool: ... +def ismount(path: _PathType) -> bool: ... + +if sys.version_info < (3, 0): + # Make sure signatures are disjunct, and allow combinations of bytes and unicode. + # (Since Python 2 allows that, too) + # Note that e.g. os.path.join("a", "b", "c", "d", u"e") will still result in + # a type error. + @overload + def join(__p1: bytes, *p: bytes) -> bytes: ... + @overload + def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: _PathType) -> Text: ... + @overload + def join(__p1: bytes, __p2: bytes, __p3: Text, *p: _PathType) -> Text: ... + @overload + def join(__p1: bytes, __p2: Text, *p: _PathType) -> Text: ... + @overload + def join(__p1: Text, *p: _PathType) -> 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(path: _StrPath, *paths: _StrPath) -> Text: ... + @overload + def join(path: _BytesPath, *paths: _BytesPath) -> bytes: ... +else: + def join(path: AnyStr, *paths: AnyStr) -> AnyStr: ... + +@overload +def relpath(path: _BytesPath, start: Optional[_BytesPath] = ...) -> bytes: ... +@overload +def relpath(path: _StrPath, start: Optional[_StrPath] = ...) -> Text: ... + +def samefile(path1: _PathType, path2: _PathType) -> bool: ... +def sameopenfile(fp1: int, fp2: int) -> bool: ... +def samestat(stat1: os.stat_result, stat2: os.stat_result) -> bool: ... + +if sys.version_info >= (3, 6): + @overload + def split(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + @overload + def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitdrive(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitext(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... +else: + def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + +if sys.platform == 'win32': + def splitunc(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # deprecated + +if sys.version_info < (3,): + def walk(path: AnyStr, visit: Callable[[_T, AnyStr, List[AnyStr]], Any], arg: _T) -> None: ... diff --git a/stdlib/2and3/posixpath.pyi b/stdlib/2and3/posixpath.pyi new file mode 100644 index 000000000..09663afa4 --- /dev/null +++ b/stdlib/2and3/posixpath.pyi @@ -0,0 +1,177 @@ +# NB: path.pyi and stdlib/2 and stdlib/3 must remain consistent! +# Stubs for os.path +# Ron Murawski + +import os +import sys +from typing import ( + overload, List, Any, AnyStr, Sequence, Tuple, BinaryIO, TextIO, + TypeVar, Union, Text, Callable, Optional +) + +_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 +# aliases (also in os) +curdir: str +pardir: str +sep: str +altsep: str +extsep: str +pathsep: str +defpath: str +devnull: str + +# ----- os.path function stubs ----- +if sys.version_info >= (3, 6): + # Overloads are necessary to work around python/mypy#3644. + @overload + def abspath(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def abspath(path: AnyStr) -> AnyStr: ... + @overload + def basename(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def basename(path: AnyStr) -> AnyStr: ... + @overload + def dirname(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def dirname(path: AnyStr) -> AnyStr: ... + @overload + def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def expanduser(path: AnyStr) -> AnyStr: ... + @overload + def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def expandvars(path: AnyStr) -> AnyStr: ... + @overload + def normcase(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def normcase(path: AnyStr) -> AnyStr: ... + @overload + def normpath(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def normpath(path: AnyStr) -> AnyStr: ... + if sys.platform == 'win32': + @overload + def realpath(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def realpath(path: AnyStr) -> AnyStr: ... + else: + @overload + def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def realpath(filename: AnyStr) -> AnyStr: ... + +else: + def abspath(path: AnyStr) -> AnyStr: ... + def basename(path: AnyStr) -> AnyStr: ... + def dirname(path: AnyStr) -> AnyStr: ... + def expanduser(path: AnyStr) -> AnyStr: ... + def expandvars(path: AnyStr) -> AnyStr: ... + def normcase(path: AnyStr) -> AnyStr: ... + def normpath(path: AnyStr) -> AnyStr: ... + if sys.platform == 'win32': + def realpath(path: AnyStr) -> AnyStr: ... + 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: ... +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(list: Sequence[_PathType]) -> Any: ... + +if sys.version_info >= (3, 3): + def exists(path: Union[_PathType, int]) -> bool: ... +else: + def exists(path: _PathType) -> bool: ... +def lexists(path: _PathType) -> bool: ... + +# These return float if os.stat_float_times() == True, +# but int is a subclass of float. +def getatime(path: _PathType) -> float: ... +def getmtime(path: _PathType) -> float: ... +def getctime(path: _PathType) -> float: ... + +def getsize(path: _PathType) -> int: ... +def isabs(path: _PathType) -> bool: ... +def isfile(path: _PathType) -> bool: ... +def isdir(path: _PathType) -> bool: ... +def islink(path: _PathType) -> bool: ... +def ismount(path: _PathType) -> bool: ... + +if sys.version_info < (3, 0): + # Make sure signatures are disjunct, and allow combinations of bytes and unicode. + # (Since Python 2 allows that, too) + # Note that e.g. os.path.join("a", "b", "c", "d", u"e") will still result in + # a type error. + @overload + def join(__p1: bytes, *p: bytes) -> bytes: ... + @overload + def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: _PathType) -> Text: ... + @overload + def join(__p1: bytes, __p2: bytes, __p3: Text, *p: _PathType) -> Text: ... + @overload + def join(__p1: bytes, __p2: Text, *p: _PathType) -> Text: ... + @overload + def join(__p1: Text, *p: _PathType) -> 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(path: _StrPath, *paths: _StrPath) -> Text: ... + @overload + def join(path: _BytesPath, *paths: _BytesPath) -> bytes: ... +else: + def join(path: AnyStr, *paths: AnyStr) -> AnyStr: ... + +@overload +def relpath(path: _BytesPath, start: Optional[_BytesPath] = ...) -> bytes: ... +@overload +def relpath(path: _StrPath, start: Optional[_StrPath] = ...) -> Text: ... + +def samefile(path1: _PathType, path2: _PathType) -> bool: ... +def sameopenfile(fp1: int, fp2: int) -> bool: ... +def samestat(stat1: os.stat_result, stat2: os.stat_result) -> bool: ... + +if sys.version_info >= (3, 6): + @overload + def split(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + @overload + def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitdrive(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitext(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... +else: + def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + +if sys.platform == 'win32': + def splitunc(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # deprecated + +if sys.version_info < (3,): + def walk(path: AnyStr, visit: Callable[[_T, AnyStr, List[AnyStr]], Any], arg: _T) -> None: ... diff --git a/stdlib/3/macpath.pyi b/stdlib/3/macpath.pyi deleted file mode 100644 index 20a0da8fd..000000000 --- a/stdlib/3/macpath.pyi +++ /dev/null @@ -1,48 +0,0 @@ -# NB: posixpath.pyi, ntpath.pyi, and macpath.pyi must remain consistent! -# Stubs for os.path -# Ron Murawski - -# based on http://docs.python.org/3.2/library/os.path.html -import sys -from typing import Any, List, Tuple, IO - -# ----- os.path variables ----- -supports_unicode_filenames = False - -# ----- os.path function stubs ----- -def abspath(path: str) -> str: ... -def basename(path) -> str: ... -def commonprefix(list: List[str]) -> str: ... -def dirname(path: str) -> str: ... -def exists(path: str) -> bool: ... -def lexists(path: str) -> bool: ... -def expanduser(path: str) -> str: ... -def expandvars(path: str) -> str: ... -def getatime(path: str) -> int: - ... # return float if os.stat_float_times() returns True -def getmtime(path: str) -> int: - ... # return float if os.stat_float_times() returns True -def getctime(path: str) -> int: - ... # return float if os.stat_float_times() returns True -def getsize(path: str) -> int: ... -def isabs(path: str) -> bool: ... -def isfile(path: str) -> bool: ... -def isdir(path: str) -> bool: ... -def islink(path: str) -> bool: ... -def ismount(path: str) -> bool: ... -def join(path: str, *paths: str) -> str: ... -def normcase(path: str) -> str: ... -def normpath(path: str) -> str: ... -def realpath(path: str) -> str: ... -def relpath(path: str, start: str = ...) -> str: ... -def samefile(path1: str, path2: str) -> bool: ... - -def sameopenfile(fp1: IO[Any], fp2: IO[Any]) -> bool: ... - -# def samestat(stat1: stat_result, stat2: stat_result) -> bool: -# ... # Unix only -def split(path: str) -> Tuple[str, str]: ... -def splitdrive(path: str) -> Tuple[str, str]: ... -def splitext(path: str) -> Tuple[str, str]: ... -if sys.version_info < (3, 7) and sys.platform == 'win32': - def splitunc(path: str) -> Tuple[str, str]: ... diff --git a/stdlib/3/ntpath.pyi b/stdlib/3/ntpath.pyi deleted file mode 100644 index 20a0da8fd..000000000 --- a/stdlib/3/ntpath.pyi +++ /dev/null @@ -1,48 +0,0 @@ -# NB: posixpath.pyi, ntpath.pyi, and macpath.pyi must remain consistent! -# Stubs for os.path -# Ron Murawski - -# based on http://docs.python.org/3.2/library/os.path.html -import sys -from typing import Any, List, Tuple, IO - -# ----- os.path variables ----- -supports_unicode_filenames = False - -# ----- os.path function stubs ----- -def abspath(path: str) -> str: ... -def basename(path) -> str: ... -def commonprefix(list: List[str]) -> str: ... -def dirname(path: str) -> str: ... -def exists(path: str) -> bool: ... -def lexists(path: str) -> bool: ... -def expanduser(path: str) -> str: ... -def expandvars(path: str) -> str: ... -def getatime(path: str) -> int: - ... # return float if os.stat_float_times() returns True -def getmtime(path: str) -> int: - ... # return float if os.stat_float_times() returns True -def getctime(path: str) -> int: - ... # return float if os.stat_float_times() returns True -def getsize(path: str) -> int: ... -def isabs(path: str) -> bool: ... -def isfile(path: str) -> bool: ... -def isdir(path: str) -> bool: ... -def islink(path: str) -> bool: ... -def ismount(path: str) -> bool: ... -def join(path: str, *paths: str) -> str: ... -def normcase(path: str) -> str: ... -def normpath(path: str) -> str: ... -def realpath(path: str) -> str: ... -def relpath(path: str, start: str = ...) -> str: ... -def samefile(path1: str, path2: str) -> bool: ... - -def sameopenfile(fp1: IO[Any], fp2: IO[Any]) -> bool: ... - -# def samestat(stat1: stat_result, stat2: stat_result) -> bool: -# ... # Unix only -def split(path: str) -> Tuple[str, str]: ... -def splitdrive(path: str) -> Tuple[str, str]: ... -def splitext(path: str) -> Tuple[str, str]: ... -if sys.version_info < (3, 7) and sys.platform == 'win32': - def splitunc(path: str) -> Tuple[str, str]: ... diff --git a/stdlib/3/posixpath.pyi b/stdlib/3/posixpath.pyi deleted file mode 100644 index 20a0da8fd..000000000 --- a/stdlib/3/posixpath.pyi +++ /dev/null @@ -1,48 +0,0 @@ -# NB: posixpath.pyi, ntpath.pyi, and macpath.pyi must remain consistent! -# Stubs for os.path -# Ron Murawski - -# based on http://docs.python.org/3.2/library/os.path.html -import sys -from typing import Any, List, Tuple, IO - -# ----- os.path variables ----- -supports_unicode_filenames = False - -# ----- os.path function stubs ----- -def abspath(path: str) -> str: ... -def basename(path) -> str: ... -def commonprefix(list: List[str]) -> str: ... -def dirname(path: str) -> str: ... -def exists(path: str) -> bool: ... -def lexists(path: str) -> bool: ... -def expanduser(path: str) -> str: ... -def expandvars(path: str) -> str: ... -def getatime(path: str) -> int: - ... # return float if os.stat_float_times() returns True -def getmtime(path: str) -> int: - ... # return float if os.stat_float_times() returns True -def getctime(path: str) -> int: - ... # return float if os.stat_float_times() returns True -def getsize(path: str) -> int: ... -def isabs(path: str) -> bool: ... -def isfile(path: str) -> bool: ... -def isdir(path: str) -> bool: ... -def islink(path: str) -> bool: ... -def ismount(path: str) -> bool: ... -def join(path: str, *paths: str) -> str: ... -def normcase(path: str) -> str: ... -def normpath(path: str) -> str: ... -def realpath(path: str) -> str: ... -def relpath(path: str, start: str = ...) -> str: ... -def samefile(path1: str, path2: str) -> bool: ... - -def sameopenfile(fp1: IO[Any], fp2: IO[Any]) -> bool: ... - -# def samestat(stat1: stat_result, stat2: stat_result) -> bool: -# ... # Unix only -def split(path: str) -> Tuple[str, str]: ... -def splitdrive(path: str) -> Tuple[str, str]: ... -def splitext(path: str) -> Tuple[str, str]: ... -if sys.version_info < (3, 7) and sys.platform == 'win32': - def splitunc(path: str) -> Tuple[str, str]: ... diff --git a/tests/check_consistent.py b/tests/check_consistent.py index f63dcc86e..39d5aaa9c 100755 --- a/tests/check_consistent.py +++ b/tests/check_consistent.py @@ -9,8 +9,9 @@ import filecmp consistent_files = [ {'stdlib/2/builtins.pyi', 'stdlib/2/__builtin__.pyi'}, {'stdlib/2/SocketServer.pyi', 'stdlib/3/socketserver.pyi'}, - {'stdlib/2/os2emxpath.pyi', 'stdlib/2/posixpath.pyi', 'stdlib/2/ntpath.pyi', 'stdlib/2/macpath.pyi'}, - {'stdlib/3/ntpath.pyi', 'stdlib/3/posixpath.pyi', 'stdlib/3/macpath.pyi', 'stdlib/3/posixpath.pyi'}, + {'stdlib/2/os2emxpath.pyi', 'stdlib/2and3/posixpath.pyi', + 'stdlib/2and3/ntpath.pyi', 'stdlib/2and3/macpath.pyi', + 'stdlib/2/os/path.pyi', 'stdlib/3/os/path.pyi'}, {'stdlib/3/enum.pyi', 'third_party/2/enum.pyi'}, {'stdlib/2/os/path.pyi', 'stdlib/3/os/path.pyi'}, {'stdlib/3/unittest/mock.pyi', 'third_party/2and3/mock.pyi'},