From 256e1ee4712c22ad9c52d0cba3eb7f3d93952974 Mon Sep 17 00:00:00 2001 From: barneygale Date: Thu, 25 May 2023 23:04:44 +0100 Subject: [PATCH] GH-104947: Make pathlib.PureWindowsPath comparisons consistent across OSs Use `str.lower()` rather than `ntpath.normcase()` to normalize case of Windows paths. This restores behaviour from Python 3.11. --- Lib/pathlib.py | 5 ++++- .../Library/2023-05-25-22-54-20.gh-issue-104947.hi6TUr.rst | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2023-05-25-22-54-20.gh-issue-104947.hi6TUr.rst diff --git a/Lib/pathlib.py b/Lib/pathlib.py index fb78939dcc31ba..c8931687a3c6dc 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -421,7 +421,10 @@ def _str_normcase(self): try: return self._str_normcase_cached except AttributeError: - self._str_normcase_cached = self._flavour.normcase(str(self)) + if _is_case_sensitive(self._flavour): + self._str_normcase_cached = str(self) + else: + self._str_normcase_cached = str(self).lower() return self._str_normcase_cached @property diff --git a/Misc/NEWS.d/next/Library/2023-05-25-22-54-20.gh-issue-104947.hi6TUr.rst b/Misc/NEWS.d/next/Library/2023-05-25-22-54-20.gh-issue-104947.hi6TUr.rst new file mode 100644 index 00000000000000..778b305aae4560 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-05-25-22-54-20.gh-issue-104947.hi6TUr.rst @@ -0,0 +1,2 @@ +Make comparisons between :class:`pathlib.PureWindowsPath` objects consistent +across Windows and Posix.