Skip to content

Commit

Permalink
Annotate pathlib.Path.{owner,group,is_mount} on windows (#13613)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenham authored Mar 11, 2025
1 parent d04d532 commit 28106bc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 51 deletions.
14 changes: 0 additions & 14 deletions stdlib/@tests/stubtest_allowlists/win32-py310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
# =============================================================
Expand All @@ -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
14 changes: 0 additions & 14 deletions stdlib/@tests/stubtest_allowlists/win32-py311.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
# =============================================================
Expand All @@ -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
4 changes: 0 additions & 4 deletions stdlib/@tests/stubtest_allowlists/win32-py312.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 0 additions & 14 deletions stdlib/@tests/stubtest_allowlists/win32-py39.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
# =============================================================
Expand All @@ -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
16 changes: 11 additions & 5 deletions stdlib/pathlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: ...
Expand All @@ -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):
Expand Down

0 comments on commit 28106bc

Please sign in to comment.