]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-104947: Make pathlib.PureWindowsPath comparisons consistent across platforms ...
authorBarney Gale <barney.gale@gmail.com>
Fri, 26 May 2023 18:04:02 +0000 (19:04 +0100)
committerGitHub <noreply@github.com>
Fri, 26 May 2023 18:04:02 +0000 (18:04 +0000)
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 <greg@krypto.org>
Lib/pathlib.py
Lib/test/test_pathlib.py
Misc/NEWS.d/next/Library/2023-05-25-22-54-20.gh-issue-104947.hi6TUr.rst [new file with mode: 0644]

index fb78939dcc31bade5ba6a580df9df592135482c5..c8931687a3c6dceae9a4a6a574a0025a64a021c9 100644 (file)
@@ -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
index 8b68cdc9b7d0036b47c9e3c30bd9016e386d5057..ef202b751e44e91db240e83005952411fdbbbe44 100644 (file)
@@ -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 (file)
index 0000000..4af73d7
--- /dev/null
@@ -0,0 +1,2 @@
+Make comparisons between :class:`pathlib.PureWindowsPath` objects consistent
+across Windows and Posix to match 3.11 behavior.