mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-28 14:46:55 +08:00
More fixes related to PathLike (#1061)
* Make DirEntry generic over AnyStr, and inherit from PathLike if it exists * Make pathlib require PathLike[str] (when it exists)
This commit is contained in:
committed by
Jelle Zijlstra
parent
7587e7f1c1
commit
af2fadc180
@@ -118,13 +118,27 @@ if sys.version_info >= (3, 6):
|
||||
|
||||
_PathType = Union[bytes, Text]
|
||||
|
||||
if sys.version_info >= (3, 5):
|
||||
class DirEntry:
|
||||
if sys.version_info >= (3, 6):
|
||||
class DirEntry(PathLike[AnyStr]):
|
||||
# This is what the scandir interator yields
|
||||
# The constructor is hidden
|
||||
|
||||
name = ''
|
||||
path = ''
|
||||
name = ... # type: AnyStr
|
||||
path = ... # type: AnyStr
|
||||
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: ...
|
||||
|
||||
def __fspath__(self) -> AnyStr: ...
|
||||
elif sys.version_info >= (3, 5):
|
||||
class DirEntry(Generic[AnyStr]):
|
||||
# This is what the scandir interator yields
|
||||
# The constructor is hidden
|
||||
|
||||
name = ... # type: AnyStr
|
||||
path = ... # type: AnyStr
|
||||
def inode(self) -> int: ...
|
||||
def is_dir(self, follow_symlinks: bool = ...) -> bool: ...
|
||||
def is_file(self, follow_symlinks: bool = ...) -> bool: ...
|
||||
@@ -308,9 +322,9 @@ if sys.version_info >= (3, 3):
|
||||
def rmdir(path: _PathType) -> None: ...
|
||||
if sys.version_info >= (3, 5):
|
||||
@overload
|
||||
def scandir(path: str = ...) -> Iterator[DirEntry]: ...
|
||||
def scandir(path: str = ...) -> Iterator[DirEntry[str]]: ...
|
||||
@overload
|
||||
def scandir(path: bytes) -> Iterator[DirEntry]: ...
|
||||
def scandir(path: bytes) -> Iterator[DirEntry[bytes]]: ...
|
||||
def stat(path: _PathType) -> stat_result: ...
|
||||
def stat_float_times(newvalue: Union[bool, None] = ...) -> bool: ...
|
||||
def statvfs(path: _PathType) -> statvfs_result: ... # Unix only
|
||||
|
||||
Reference in New Issue
Block a user