diff --git a/stdlib/2/os/__init__.pyi b/stdlib/2/os/__init__.pyi index da2a35dd1..63407c289 100644 --- a/stdlib/2/os/__init__.pyi +++ b/stdlib/2/os/__init__.pyi @@ -3,7 +3,7 @@ from builtins import OSError as error from io import TextIOWrapper as _TextIOWrapper -from posix import stat_result as stat_result # TODO: use this, see https://github.com/python/mypy/issues/3078 +from posix import listdir as listdir, stat_result as stat_result # TODO: use this, see https://github.com/python/mypy/issues/3078 import sys from typing import ( Mapping, MutableMapping, Dict, List, Any, Tuple, Iterator, overload, Union, AnyStr, @@ -200,7 +200,6 @@ def getcwd() -> str: ... def getcwdu() -> unicode: ... def chmod(path: _PathType, mode: int) -> None: ... def link(src: _PathType, link_name: _PathType) -> None: ... -def listdir(path: AnyStr) -> List[AnyStr]: ... def lstat(path: _PathType) -> Any: ... def mknod(filename: _PathType, mode: int = ..., device: int = ...) -> None: ... def major(device: int) -> int: ... diff --git a/stdlib/2/posix.pyi b/stdlib/2/posix.pyi index fcd4a66f9..c6ff52ccf 100644 --- a/stdlib/2/posix.pyi +++ b/stdlib/2/posix.pyi @@ -1,4 +1,4 @@ -from typing import Dict, List, Mapping, Tuple, Union, Sequence, IO, Optional, TypeVar +from typing import AnyStr, Dict, List, Mapping, Tuple, Union, Sequence, IO, Optional, TypeVar error = OSError @@ -7,6 +7,8 @@ environ: Dict[str, str] pathconf_names: Dict[str, int] sysconf_names: Dict[str, int] +_T = TypeVar("_T") + EX_CANTCREAT: int EX_CONFIG: int EX_DATAERR: int @@ -143,8 +145,7 @@ def kill(pid: int, sig: int) -> None: ... def killpg(pgid: int, sig: int) -> None: ... def lchown(path: unicode, uid: int, gid: int) -> None: ... def link(source: unicode, link_name: str) -> None: ... -_T = TypeVar("_T") -def listdir(path: _T) -> List[_T]: ... +def listdir(path: AnyStr) -> List[AnyStr]: ... def lseek(fd: int, pos: int, how: int) -> None: ... def lstat(path: unicode) -> stat_result: ... def major(device: int) -> int: ... diff --git a/stdlib/3/os/__init__.pyi b/stdlib/3/os/__init__.pyi index 2a9656a3d..458fc75c1 100644 --- a/stdlib/3/os/__init__.pyi +++ b/stdlib/3/os/__init__.pyi @@ -2,7 +2,7 @@ # Ron Murawski from io import TextIOWrapper as _TextIOWrapper -from posix import times_result +from posix import listdir as listdir, times_result import sys from typing import ( Mapping, MutableMapping, Dict, List, Any, Tuple, IO, Iterable, Iterator, NoReturn, overload, Union, AnyStr, @@ -434,23 +434,6 @@ def link( follow_symlinks: bool = ..., ) -> None: ... -if sys.version_info >= (3, 6): - @overload - def listdir(path: Optional[str] = ...) -> List[str]: ... - @overload - def listdir(path: bytes) -> List[bytes]: ... - @overload - def listdir(path: int) -> List[str]: ... - @overload - def listdir(path: PathLike[str]) -> List[str]: ... -else: - @overload - def listdir(path: Optional[str] = ...) -> List[str]: ... - @overload - def listdir(path: bytes) -> List[bytes]: ... - @overload - def listdir(path: int) -> List[str]: ... - def lstat(path: _PathType, *, dir_fd: Optional[int] = ...) -> stat_result: ... def mkdir(path: _PathType, mode: int = ..., *, dir_fd: Optional[int] = ...) -> None: ... if sys.platform != 'win32': diff --git a/stdlib/3/posix.pyi b/stdlib/3/posix.pyi index a24001d7f..83537cfbc 100644 --- a/stdlib/3/posix.pyi +++ b/stdlib/3/posix.pyi @@ -3,10 +3,13 @@ # NOTE: These are incomplete! import sys -from typing import NamedTuple, Tuple +from typing import List, NamedTuple, Optional, overload, Tuple from os import stat_result as stat_result +if sys.version_info >= (3, 6): + from builtins import _PathLike # See comment in builtins + uname_result = NamedTuple('uname_result', [ ('sysname', str), ('nodename', str), @@ -109,3 +112,20 @@ WNOHANG: int WSTOPSIG: int WTERMSIG: int WUNTRACED: int + +if sys.version_info >= (3, 6): + @overload + def listdir(path: Optional[str] = ...) -> List[str]: ... + @overload + def listdir(path: bytes) -> List[bytes]: ... + @overload + def listdir(path: int) -> List[str]: ... + @overload + def listdir(path: _PathLike[str]) -> List[str]: ... +else: + @overload + def listdir(path: Optional[str] = ...) -> List[str]: ... + @overload + def listdir(path: bytes) -> List[bytes]: ... + @overload + def listdir(path: int) -> List[str]: ...