]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] GH-104947: Make pathlib.PureWindowsPath comparisons consistent across platform...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 26 May 2023 18:33:09 +0000 (11:33 -0700)
committerGitHub <noreply@github.com>
Fri, 26 May 2023 18:33:09 +0000 (18:33 +0000)
Use `str.lower()` rather than `ntpath.normcase()` to normalize case of
Windows paths. This restores behaviour from Python 3.11.

(cherry picked from commit ad0be361c9922a918c7c3eaf83e1d8f2b019279c)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
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 3d68c161603d0876d8e9a9c8c0665b9365960d5b..bfe26e1e167953e9986ca7c8f6b6ca77a07de6e6 100644 (file)
@@ -421,7 +421,10 @@ class PurePath(object):
         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 ab2c2b232a04115fc68d8267019e9491b6a103c2..bc2947ec95b3052d067918b7598bfa826c1bc426 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.