mirror of
https://github.com/python/cpython.git
synced 2025-07-19 01:05:26 +00:00
GH-103631: Fix PurePosixPath(PureWindowsPath(...))
separator handling (GH-104949)
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>
This commit is contained in:
parent
ad0be361c9
commit
328422ce61
3 changed files with 11 additions and 0 deletions
|
@ -300,6 +300,9 @@ class PurePath(os.PathLike):
|
|||
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)
|
||||
|
|
|
@ -789,6 +789,12 @@ class PurePosixPathTest(_BasePurePathTest, unittest.TestCase):
|
|||
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
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Fix ``pathlib.PurePosixPath(pathlib.PureWindowsPath(...))`` not converting
|
||||
path separators to restore 3.11 compatible behavior.
|
Loading…
Add table
Add a link
Reference in a new issue