From 28106bcb73835713231095f108f0994845092403 Mon Sep 17 00:00:00 2001 From: Joren Hammudoglu Date: Tue, 11 Mar 2025 18:45:40 +0100 Subject: [PATCH] Annotate `pathlib.Path.{owner,group,is_mount}` on windows (#13613) --- .../@tests/stubtest_allowlists/win32-py310.txt | 14 -------------- .../@tests/stubtest_allowlists/win32-py311.txt | 14 -------------- .../@tests/stubtest_allowlists/win32-py312.txt | 4 ---- stdlib/@tests/stubtest_allowlists/win32-py39.txt | 14 -------------- stdlib/pathlib.pyi | 16 +++++++++++----- 5 files changed, 11 insertions(+), 51 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/win32-py310.txt b/stdlib/@tests/stubtest_allowlists/win32-py310.txt index 555f97cd4..4bc95349e 100644 --- a/stdlib/@tests/stubtest_allowlists/win32-py310.txt +++ b/stdlib/@tests/stubtest_allowlists/win32-py310.txt @@ -44,16 +44,6 @@ xml.parsers.expat.XMLParserType.SetReparseDeferralEnabled xml.sax.expatreader.ExpatParser.flush -# ============================================================= -# Allowlist entries that cannot or should not be fixed; <= 3.11 -# ============================================================= - -# pathlib methods that exist on Windows, but always raise NotImplementedError, -# so are omitted from the stub -pathlib.Path.is_mount -pathlib.WindowsPath.is_mount - - # ============================================================= # Allowlist entries that cannot or should not be fixed; <= 3.12 # ============================================================= @@ -63,7 +53,3 @@ crypt nis ossaudiodev spwd - -# pathlib functions that rely on modules that don't exist on Windows -pathlib.Path.owner -pathlib.Path.group diff --git a/stdlib/@tests/stubtest_allowlists/win32-py311.txt b/stdlib/@tests/stubtest_allowlists/win32-py311.txt index 0078cb026..771e0a090 100644 --- a/stdlib/@tests/stubtest_allowlists/win32-py311.txt +++ b/stdlib/@tests/stubtest_allowlists/win32-py311.txt @@ -11,16 +11,6 @@ email.utils.getaddresses email.utils.parseaddr -# ============================================================= -# Allowlist entries that cannot or should not be fixed; <= 3.11 -# ============================================================= - -# pathlib methods that exist on Windows, but always raise NotImplementedError, -# so are omitted from the stub -pathlib.Path.is_mount -pathlib.WindowsPath.is_mount - - # ============================================================= # Allowlist entries that cannot or should not be fixed; <= 3.12 # ============================================================= @@ -30,7 +20,3 @@ crypt nis ossaudiodev spwd - -# pathlib functions that rely on modules that don't exist on Windows -pathlib.Path.owner -pathlib.Path.group diff --git a/stdlib/@tests/stubtest_allowlists/win32-py312.txt b/stdlib/@tests/stubtest_allowlists/win32-py312.txt index aa2a6d303..8c7e5fa72 100644 --- a/stdlib/@tests/stubtest_allowlists/win32-py312.txt +++ b/stdlib/@tests/stubtest_allowlists/win32-py312.txt @@ -25,7 +25,3 @@ crypt nis ossaudiodev spwd - -# pathlib functions that rely on modules that don't exist on Windows -pathlib.Path.owner -pathlib.Path.group diff --git a/stdlib/@tests/stubtest_allowlists/win32-py39.txt b/stdlib/@tests/stubtest_allowlists/win32-py39.txt index d2b82ecdc..40a525566 100644 --- a/stdlib/@tests/stubtest_allowlists/win32-py39.txt +++ b/stdlib/@tests/stubtest_allowlists/win32-py39.txt @@ -53,16 +53,6 @@ xml.parsers.expat.XMLParserType.SetReparseDeferralEnabled xml.sax.expatreader.ExpatParser.flush -# ============================================================= -# Allowlist entries that cannot or should not be fixed; <= 3.11 -# ============================================================= - -# pathlib methods that exist on Windows, but always raise NotImplementedError, -# so are omitted from the stub -pathlib.Path.is_mount -pathlib.WindowsPath.is_mount - - # ============================================================= # Allowlist entries that cannot or should not be fixed; <= 3.12 # ============================================================= @@ -72,7 +62,3 @@ crypt nis ossaudiodev spwd - -# pathlib functions that rely on modules that don't exist on Windows -pathlib.Path.owner -pathlib.Path.group diff --git a/stdlib/pathlib.pyi b/stdlib/pathlib.pyi index e2a816ae1..a18aed4ba 100644 --- a/stdlib/pathlib.pyi +++ b/stdlib/pathlib.pyi @@ -16,7 +16,7 @@ from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWra from os import PathLike, stat_result from types import TracebackType from typing import IO, Any, BinaryIO, ClassVar, Literal, overload -from typing_extensions import Self, deprecated +from typing_extensions import Never, Self, deprecated if sys.version_info >= (3, 9): from types import GenericAlias @@ -226,9 +226,13 @@ class Path(PurePath): def open( self, mode: str, buffering: int = -1, encoding: str | None = None, errors: str | None = None, newline: str | None = None ) -> IO[Any]: ... - if sys.platform != "win32": - # These methods do "exist" on Windows, but they always raise NotImplementedError, - # so it's safer to pretend they don't exist + + # These methods do "exist" on Windows on <3.13, but they always raise NotImplementedError. + if sys.platform == "win32": + if sys.version_info < (3, 13): + def owner(self: Never) -> str: ... # type: ignore[misc] + def group(self: Never) -> str: ... # type: ignore[misc] + else: if sys.version_info >= (3, 13): def owner(self, *, follow_symlinks: bool = True) -> str: ... def group(self, *, follow_symlinks: bool = True) -> str: ... @@ -238,7 +242,9 @@ class Path(PurePath): # This method does "exist" on Windows on <3.12, but always raises NotImplementedError # On py312+, it works properly on Windows, as with all other platforms - if sys.platform != "win32" or sys.version_info >= (3, 12): + if sys.platform == "win32" and sys.version_info < (3, 12): + def is_mount(self: Never) -> bool: ... # type: ignore[misc] + else: def is_mount(self) -> bool: ... if sys.version_info >= (3, 9):