From 2949a9289ebdf2d3af427f9b5f5a4d4dbd0005a0 Mon Sep 17 00:00:00 2001 From: Dominic Davis-Foster Date: Wed, 11 Nov 2020 18:19:35 +0000 Subject: [PATCH] Annotate pathlib.Path methods as returning the same type even when subclassed. (#4755) --- stdlib/3/pathlib.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/3/pathlib.pyi b/stdlib/3/pathlib.pyi index 7145f4152..975422c8f 100644 --- a/stdlib/3/pathlib.pyi +++ b/stdlib/3/pathlib.pyi @@ -61,7 +61,7 @@ class PureWindowsPath(PurePath): ... class Path(PurePath): def __new__(cls: Type[_P], *args: Union[str, _PathLike], **kwargs: Any) -> _P: ... - def __enter__(self) -> Path: ... + def __enter__(self: _P) -> _P: ... def __exit__( self, exc_type: Optional[Type[BaseException]], exc_value: Optional[BaseException], traceback: Optional[TracebackType] ) -> Optional[bool]: ... @@ -70,7 +70,7 @@ class Path(PurePath): def stat(self) -> os.stat_result: ... def chmod(self, mode: int) -> None: ... def exists(self) -> bool: ... - def glob(self, pattern: str) -> Generator[Path, None, None]: ... + def glob(self: _P, pattern: str) -> Generator[_P, None, None]: ... def group(self) -> str: ... def is_dir(self) -> bool: ... def is_file(self) -> bool: ... @@ -81,7 +81,7 @@ class Path(PurePath): def is_fifo(self) -> bool: ... def is_block_device(self) -> bool: ... def is_char_device(self) -> bool: ... - def iterdir(self) -> Generator[Path, None, None]: ... + def iterdir(self: _P) -> Generator[_P, None, None]: ... def lchmod(self, mode: int) -> None: ... def lstat(self) -> os.stat_result: ... def mkdir(self, mode: int = ..., parents: bool = ..., exist_ok: bool = ...) -> None: ... @@ -154,7 +154,7 @@ class Path(PurePath): def rename(self, target: Union[str, PurePath]) -> None: ... def replace(self, target: Union[str, PurePath]) -> None: ... def resolve(self: _P, strict: bool = ...) -> _P: ... - def rglob(self, pattern: str) -> Generator[Path, None, None]: ... + def rglob(self: _P, pattern: str) -> Generator[_P, None, None]: ... def rmdir(self) -> None: ... def symlink_to(self, target: Union[str, Path], target_is_directory: bool = ...) -> None: ... def touch(self, mode: int = ..., exist_ok: bool = ...) -> None: ...