[3.12] GH-125069: Fix inconsistent joining in WindowsPath(PosixPath(...)) (GH-125156) (#125410)

`PurePath.__init__()` incorrectly uses the `_raw_paths` of a given
`PurePath` object with a different flavour, even though the procedure to
join path segments can differ between flavours.

This change makes the `_raw_paths`-enabled deferred joining apply _only_
when the path flavours match.

(cherry picked from commit cb8e5995d8)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
Barney Gale 2024-10-13 19:18:41 +01:00 committed by GitHub
parent 243a8a9d68
commit f49221af46
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 2 deletions

View file

@ -359,9 +359,9 @@ class PurePath(object):
paths = []
for arg in args:
if isinstance(arg, PurePath):
if arg._flavour is ntpath and self._flavour is posixpath:
if arg._flavour is not self._flavour:
# GH-103631: Convert separators for backwards compatibility.
paths.extend(path.replace('\\', '/') for path in arg._raw_paths)
paths.append(arg.as_posix())
else:
paths.extend(arg._raw_paths)
else: