From: Barney Gale Date: Fri, 26 May 2023 18:04:02 +0000 (+0100) Subject: GH-104947: Make pathlib.PureWindowsPath comparisons consistent across platforms ... X-Git-Tag: v3.13.0a1~2006 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad0be361c9922a918c7c3eaf83e1d8f2b019279c;p=thirdparty%2FPython%2Fcpython.git GH-104947: Make pathlib.PureWindowsPath comparisons consistent across platforms (GH-104948) Use `str.lower()` rather than `ntpath.normcase()` to normalize case of Windows paths. This restores behaviour from Python 3.11. Co-authored-by: Gregory P. Smith --- diff --git a/Lib/pathlib.py b/Lib/pathlib.py index fb78939dcc31..c8931687a3c6 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -421,7 +421,10 @@ class PurePath(os.PathLike): 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/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index 8b68cdc9b7d0..ef202b751e44 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -904,6 +904,7 @@ class PureWindowsPathTest(_BasePurePathTest, unittest.TestCase): self.assertEqual(P('a/B'), P('A/b')) self.assertEqual(P('C:a/B'), P('c:A/b')) self.assertEqual(P('//Some/SHARE/a/B'), P('//somE/share/A/b')) + self.assertEqual(P('\u0130'), P('i\u0307')) def test_as_uri(self): P = self.cls 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 000000000000..4af73d73d2a7 --- /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 to match 3.11 behavior.