From d315ceb0603d88ee3a9458346a86d4f3f36f3297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Thu, 4 Aug 2016 00:40:00 +0200 Subject: [PATCH] Add os.scandir and os.DirEntry (#424) Introduced in Python 3.5 --- stdlib/3/os/__init__.pyi | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/stdlib/3/os/__init__.pyi b/stdlib/3/os/__init__.pyi index be9cbbda5..e7818420f 100644 --- a/stdlib/3/os/__init__.pyi +++ b/stdlib/3/os/__init__.pyi @@ -105,6 +105,20 @@ WNOHANG = 0 # Unix only TMP_MAX = 0 # Undocumented, but used by tempfile # ----- os classes (structures) ----- +if sys.version_info >= (3, 5): + class DirEntry: + # This is what the scandir interator yields + # The constructor is hidden + + name = '' + path = '' + def inode(self) -> int: ... + def is_dir(self, follow_symlinks: bool = ...) -> bool: ... + def is_file(self, follow_symlinks: bool = ...) -> bool: ... + def is_symlink(self) -> bool: ... + def stat(self) -> stat_result: ... + + class stat_result: # For backward compatibility, the return value of stat() is also # accessible as a tuple of at least 10 integers giving the most important @@ -259,6 +273,11 @@ def renames(old: AnyStr, new: AnyStr) -> None: ... if sys.version_info >= (3, 3): def replace(src: AnyStr, dst: AnyStr) -> None: ... def rmdir(path: AnyStr) -> None: ... +if sys.version_info >= (3, 5): + @overload + def scandir(path: str = ...) -> Iterator[DirEntry]: ... + @overload + def scandir(path: bytes) -> Iterator[DirEntry]: ... def stat(path: AnyStr) -> stat_result: ... def stat_float_times(newvalue: Union[bool, None] = ...) -> bool: ... def statvfs(path: str) -> statvfs_result: ... # Unix only