From b89c894650b4bf36d7b3a32e4d7d17dacebb9e14 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Fri, 28 Oct 2022 17:17:58 +0300 Subject: [PATCH 1/5] Improve types and `bytes` usage of `pathlib` --- stdlib/pathlib.pyi | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/stdlib/pathlib.pyi b/stdlib/pathlib.pyi index 4adfc233301b..b8880c11020d 100644 --- a/stdlib/pathlib.pyi +++ b/stdlib/pathlib.pyi @@ -7,6 +7,7 @@ from _typeshed import ( OpenTextMode, Self, StrPath, + ReadableBuffer, ) from collections.abc import Callable, Generator, Iterator, Sequence from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper @@ -188,16 +189,16 @@ class Path(PurePath): def expanduser(self: Self) -> Self: ... def read_bytes(self) -> bytes: ... def read_text(self, encoding: str | None = ..., errors: str | None = ...) -> str: ... - def samefile(self, other_path: str | bytes | int | Path) -> bool: ... - def write_bytes(self, data: bytes) -> int: ... + def samefile(self, other_path: StrPath) -> bool: ... + def write_bytes(self, data: ReadableBuffer) -> int: ... if sys.version_info >= (3, 10): def write_text( self, data: str, encoding: str | None = ..., errors: str | None = ..., newline: str | None = ... ) -> int: ... else: def write_text(self, data: str, encoding: str | None = ..., errors: str | None = ...) -> int: ... - if sys.version_info >= (3, 8): - def link_to(self, target: StrPath | bytes) -> None: ... + if (3, 8) <= sys.version_info < (3, 12): + def link_to(self, target: StrPath) -> None: ... if sys.version_info >= (3, 12): def walk( self: Self, top_down: bool = ..., on_error: Callable[[OSError], object] | None = ..., follow_symlinks: bool = ... From 91633a0f3dac08afd1f3f2723a125987249f63d2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 28 Oct 2022 14:20:46 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/pathlib.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/pathlib.pyi b/stdlib/pathlib.pyi index b8880c11020d..0b0d8fa3ccf9 100644 --- a/stdlib/pathlib.pyi +++ b/stdlib/pathlib.pyi @@ -5,9 +5,9 @@ from _typeshed import ( OpenBinaryModeUpdating, OpenBinaryModeWriting, OpenTextMode, + ReadableBuffer, Self, StrPath, - ReadableBuffer, ) from collections.abc import Callable, Generator, Iterator, Sequence from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper From 6f5bb256c9db5fbf0b79aadc4d96d52327a311b2 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Fri, 28 Oct 2022 17:26:46 +0300 Subject: [PATCH 3/5] Fix ci --- stdlib/pathlib.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/pathlib.pyi b/stdlib/pathlib.pyi index b8880c11020d..7dd7a5eee2c6 100644 --- a/stdlib/pathlib.pyi +++ b/stdlib/pathlib.pyi @@ -197,7 +197,7 @@ class Path(PurePath): ) -> int: ... else: def write_text(self, data: str, encoding: str | None = ..., errors: str | None = ...) -> int: ... - if (3, 8) <= sys.version_info < (3, 12): + if sys.version_info >=(3, 8) and sys.version_info < (3, 12): def link_to(self, target: StrPath) -> None: ... if sys.version_info >= (3, 12): def walk( From c23edaee95698c204648f91bac6f28ded0cff20a Mon Sep 17 00:00:00 2001 From: sobolevn Date: Fri, 28 Oct 2022 20:08:05 +0300 Subject: [PATCH 4/5] Address review --- stdlib/pathlib.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlib/pathlib.pyi b/stdlib/pathlib.pyi index ceb5c96dc6d9..89e4c2d5fb30 100644 --- a/stdlib/pathlib.pyi +++ b/stdlib/pathlib.pyi @@ -8,6 +8,7 @@ from _typeshed import ( ReadableBuffer, Self, StrPath, + StrOrBytesPath, ) from collections.abc import Callable, Generator, Iterator, Sequence from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper @@ -197,8 +198,8 @@ class Path(PurePath): ) -> int: ... else: def write_text(self, data: str, encoding: str | None = ..., errors: str | None = ...) -> int: ... - if sys.version_info >=(3, 8) and sys.version_info < (3, 12): - def link_to(self, target: StrPath) -> None: ... + if sys.version_info >= (3, 8) and sys.version_info < (3, 12): + def link_to(self, target: StrOrBytesPath) -> None: ... if sys.version_info >= (3, 12): def walk( self: Self, top_down: bool = ..., on_error: Callable[[OSError], object] | None = ..., follow_symlinks: bool = ... From b4c23a31d950d2ab056577515f78368b068f3767 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 28 Oct 2022 17:09:47 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/pathlib.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/pathlib.pyi b/stdlib/pathlib.pyi index 89e4c2d5fb30..79c2352a0f85 100644 --- a/stdlib/pathlib.pyi +++ b/stdlib/pathlib.pyi @@ -7,8 +7,8 @@ from _typeshed import ( OpenTextMode, ReadableBuffer, Self, - StrPath, StrOrBytesPath, + StrPath, ) from collections.abc import Callable, Generator, Iterator, Sequence from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper