Skip to content

Commit

Permalink
GH-104947: Make pathlib.PureWindowsPath comparisons consistent across…
Browse files Browse the repository at this point in the history
… 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 <greg@krypto.org>
  • Loading branch information
barneygale and gpshead authored May 26, 2023
1 parent 060277d commit ad0be36
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ def test_eq(self):
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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Make comparisons between :class:`pathlib.PureWindowsPath` objects consistent
across Windows and Posix to match 3.11 behavior.

0 comments on commit ad0be36

Please sign in to comment.