Skip to content

Commit 4df9634

Browse files
Remove pathlib.PurePath.__eq__ (#10662)
Fixes #10661 Co-authored-by: Alex Waygood <[email protected]>
1 parent 06d83d4 commit 4df9634

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

stdlib/pathlib.pyi

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class PurePath(PathLike[str]):
4646
def __new__(cls, *args: StrPath) -> Self: ...
4747

4848
def __hash__(self) -> int: ...
49-
def __eq__(self, other: object) -> bool: ...
5049
def __fspath__(self) -> str: ...
5150
def __lt__(self, other: PurePath) -> bool: ...
5251
def __le__(self, other: PurePath) -> bool: ...

test_cases/stdlib/check_pathlib.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from __future__ import annotations
2+
3+
from pathlib import Path, PureWindowsPath
4+
5+
if Path("asdf") == Path("asdf"):
6+
...
7+
8+
# https://github.com/python/typeshed/issues/10661
9+
# Provide a true positive error when comparing Path to str
10+
# mypy should report a comparison-overlap error with --strict-equality,
11+
# and pyright should report a reportUnnecessaryComparison error
12+
if Path("asdf") == "asdf": # type: ignore
13+
...
14+
15+
# Errors on comparison here are technically false positives. However, this comparison is a little
16+
# interesting: it can never hold true on Posix, but could hold true on Windows. We should experiment
17+
# with more accurate __new__, such that we only get an error for such comparisons on platforms
18+
# where they can never hold true.
19+
if PureWindowsPath("asdf") == Path("asdf"): # type: ignore
20+
...

0 commit comments

Comments
 (0)