For backwards compatibility, accept backslashes as path separators in
`PurePosixPath` if an instance of `PureWindowsPath` is supplied.
This restores behaviour from Python 3.11.
Co-authored-by: Gregory P. Smith <greg@krypto.org>
for arg in args:
if isinstance(arg, PurePath):
path = arg._raw_path
+ if arg._flavour is ntpath and self._flavour is posixpath:
+ # GH-103631: Convert separators for backwards compatibility.
+ path = path.replace('\\', '/')
else:
try:
path = os.fspath(arg)
pp = P('//a') / '/c'
self.assertEqual(pp, P('/c'))
+ def test_parse_windows_path(self):
+ P = self.cls
+ p = P('c:', 'a', 'b')
+ pp = P(pathlib.PureWindowsPath('c:\\a\\b'))
+ self.assertEqual(p, pp)
+
class PureWindowsPathTest(_BasePurePathTest, unittest.TestCase):
cls = pathlib.PureWindowsPath
--- /dev/null
+Fix ``pathlib.PurePosixPath(pathlib.PureWindowsPath(...))`` not converting
+path separators to restore 3.11 compatible behavior.