Skip to content

Commit 28106bc

Browse files
authored
Annotate pathlib.Path.{owner,group,is_mount} on windows (#13613)
1 parent d04d532 commit 28106bc

File tree

5 files changed

+11
-51
lines changed

5 files changed

+11
-51
lines changed

stdlib/@tests/stubtest_allowlists/win32-py310.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,6 @@ xml.parsers.expat.XMLParserType.SetReparseDeferralEnabled
4444
xml.sax.expatreader.ExpatParser.flush
4545

4646

47-
# =============================================================
48-
# Allowlist entries that cannot or should not be fixed; <= 3.11
49-
# =============================================================
50-
51-
# pathlib methods that exist on Windows, but always raise NotImplementedError,
52-
# so are omitted from the stub
53-
pathlib.Path.is_mount
54-
pathlib.WindowsPath.is_mount
55-
56-
5747
# =============================================================
5848
# Allowlist entries that cannot or should not be fixed; <= 3.12
5949
# =============================================================
@@ -63,7 +53,3 @@ crypt
6353
nis
6454
ossaudiodev
6555
spwd
66-
67-
# pathlib functions that rely on modules that don't exist on Windows
68-
pathlib.Path.owner
69-
pathlib.Path.group

stdlib/@tests/stubtest_allowlists/win32-py311.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@ email.utils.getaddresses
1111
email.utils.parseaddr
1212

1313

14-
# =============================================================
15-
# Allowlist entries that cannot or should not be fixed; <= 3.11
16-
# =============================================================
17-
18-
# pathlib methods that exist on Windows, but always raise NotImplementedError,
19-
# so are omitted from the stub
20-
pathlib.Path.is_mount
21-
pathlib.WindowsPath.is_mount
22-
23-
2414
# =============================================================
2515
# Allowlist entries that cannot or should not be fixed; <= 3.12
2616
# =============================================================
@@ -30,7 +20,3 @@ crypt
3020
nis
3121
ossaudiodev
3222
spwd
33-
34-
# pathlib functions that rely on modules that don't exist on Windows
35-
pathlib.Path.owner
36-
pathlib.Path.group

stdlib/@tests/stubtest_allowlists/win32-py312.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,3 @@ crypt
2525
nis
2626
ossaudiodev
2727
spwd
28-
29-
# pathlib functions that rely on modules that don't exist on Windows
30-
pathlib.Path.owner
31-
pathlib.Path.group

stdlib/@tests/stubtest_allowlists/win32-py39.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,6 @@ xml.parsers.expat.XMLParserType.SetReparseDeferralEnabled
5353
xml.sax.expatreader.ExpatParser.flush
5454

5555

56-
# =============================================================
57-
# Allowlist entries that cannot or should not be fixed; <= 3.11
58-
# =============================================================
59-
60-
# pathlib methods that exist on Windows, but always raise NotImplementedError,
61-
# so are omitted from the stub
62-
pathlib.Path.is_mount
63-
pathlib.WindowsPath.is_mount
64-
65-
6656
# =============================================================
6757
# Allowlist entries that cannot or should not be fixed; <= 3.12
6858
# =============================================================
@@ -72,7 +62,3 @@ crypt
7262
nis
7363
ossaudiodev
7464
spwd
75-
76-
# pathlib functions that rely on modules that don't exist on Windows
77-
pathlib.Path.owner
78-
pathlib.Path.group

stdlib/pathlib.pyi

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWra
1616
from os import PathLike, stat_result
1717
from types import TracebackType
1818
from typing import IO, Any, BinaryIO, ClassVar, Literal, overload
19-
from typing_extensions import Self, deprecated
19+
from typing_extensions import Never, Self, deprecated
2020

2121
if sys.version_info >= (3, 9):
2222
from types import GenericAlias
@@ -226,9 +226,13 @@ class Path(PurePath):
226226
def open(
227227
self, mode: str, buffering: int = -1, encoding: str | None = None, errors: str | None = None, newline: str | None = None
228228
) -> IO[Any]: ...
229-
if sys.platform != "win32":
230-
# These methods do "exist" on Windows, but they always raise NotImplementedError,
231-
# so it's safer to pretend they don't exist
229+
230+
# These methods do "exist" on Windows on <3.13, but they always raise NotImplementedError.
231+
if sys.platform == "win32":
232+
if sys.version_info < (3, 13):
233+
def owner(self: Never) -> str: ... # type: ignore[misc]
234+
def group(self: Never) -> str: ... # type: ignore[misc]
235+
else:
232236
if sys.version_info >= (3, 13):
233237
def owner(self, *, follow_symlinks: bool = True) -> str: ...
234238
def group(self, *, follow_symlinks: bool = True) -> str: ...
@@ -238,7 +242,9 @@ class Path(PurePath):
238242

239243
# This method does "exist" on Windows on <3.12, but always raises NotImplementedError
240244
# On py312+, it works properly on Windows, as with all other platforms
241-
if sys.platform != "win32" or sys.version_info >= (3, 12):
245+
if sys.platform == "win32" and sys.version_info < (3, 12):
246+
def is_mount(self: Never) -> bool: ... # type: ignore[misc]
247+
else:
242248
def is_mount(self) -> bool: ...
243249

244250
if sys.version_info >= (3, 9):

0 commit comments

Comments
 (0)