From d48d4e915222a571fc45070062f325fb5cea7a09 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Mon, 4 Sep 2023 15:58:38 -0700 Subject: [PATCH 1/4] Remove pathlib.PurePath.__eq__ Fixes #10661 --- stdlib/pathlib.pyi | 1 - test_cases/stdlib/check_pathlib.py | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 test_cases/stdlib/check_pathlib.py diff --git a/stdlib/pathlib.pyi b/stdlib/pathlib.pyi index 4dcda98b289b..10ffa4a778e8 100644 --- a/stdlib/pathlib.pyi +++ b/stdlib/pathlib.pyi @@ -46,7 +46,6 @@ class PurePath(PathLike[str]): def __new__(cls, *args: StrPath) -> Self: ... def __hash__(self) -> int: ... - def __eq__(self, other: object) -> bool: ... def __fspath__(self) -> str: ... def __lt__(self, other: PurePath) -> bool: ... def __le__(self, other: PurePath) -> bool: ... diff --git a/test_cases/stdlib/check_pathlib.py b/test_cases/stdlib/check_pathlib.py new file mode 100644 index 000000000000..48e63a06978b --- /dev/null +++ b/test_cases/stdlib/check_pathlib.py @@ -0,0 +1,4 @@ +# pyright: strict +from pathlib import Path + +if Path("asdf") == "asdf": ... # type: ignore From 7cf01aa0a03d3a0ea9fca72dfb3924bd981dc931 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Mon, 4 Sep 2023 16:46:38 -0700 Subject: [PATCH 2/4] . --- test_cases/stdlib/check_pathlib.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test_cases/stdlib/check_pathlib.py b/test_cases/stdlib/check_pathlib.py index 48e63a06978b..9fc79f06beaa 100644 --- a/test_cases/stdlib/check_pathlib.py +++ b/test_cases/stdlib/check_pathlib.py @@ -1,4 +1,7 @@ # pyright: strict +from __future__ import annotations + from pathlib import Path -if Path("asdf") == "asdf": ... # type: ignore +if Path("asdf") == "asdf": # type: ignore + ... From c94c946326a24164bfc6c74c416438cc638b666d Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Mon, 4 Sep 2023 17:15:16 -0700 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Alex Waygood --- test_cases/stdlib/check_pathlib.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test_cases/stdlib/check_pathlib.py b/test_cases/stdlib/check_pathlib.py index 9fc79f06beaa..da69ebb3ff38 100644 --- a/test_cases/stdlib/check_pathlib.py +++ b/test_cases/stdlib/check_pathlib.py @@ -1,7 +1,8 @@ -# pyright: strict from __future__ import annotations from pathlib import Path +# make sure this causes mypy to emit a --strict-equality error, +# and pyright to report a reportUnnecessaryComparison error if Path("asdf") == "asdf": # type: ignore ... From c97353c68453571e36704e6350f0f00c1ab3ad56 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Tue, 5 Sep 2023 13:23:27 -0700 Subject: [PATCH 4/4] alex example --- test_cases/stdlib/check_pathlib.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test_cases/stdlib/check_pathlib.py b/test_cases/stdlib/check_pathlib.py index da69ebb3ff38..0b52c3669d07 100644 --- a/test_cases/stdlib/check_pathlib.py +++ b/test_cases/stdlib/check_pathlib.py @@ -1,8 +1,20 @@ from __future__ import annotations -from pathlib import Path +from pathlib import Path, PureWindowsPath -# make sure this causes mypy to emit a --strict-equality error, -# and pyright to report a reportUnnecessaryComparison error +if Path("asdf") == Path("asdf"): + ... + +# https://github.com/python/typeshed/issues/10661 +# Provide a true positive error when comparing Path to str +# mypy should report a comparison-overlap error with --strict-equality, +# and pyright should report a reportUnnecessaryComparison error if Path("asdf") == "asdf": # type: ignore ... + +# Errors on comparison here are technically false positives. However, this comparison is a little +# interesting: it can never hold true on Posix, but could hold true on Windows. We should experiment +# with more accurate __new__, such that we only get an error for such comparisons on platforms +# where they can never hold true. +if PureWindowsPath("asdf") == Path("asdf"): # type: ignore + ...