Skip to content

GH-125012: Make PurePath emit FutureWarning when converting separators #125863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions Lib/pathlib/_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,23 @@ def __init__(self, *args):
paths = []
for arg in args:
if isinstance(arg, PurePath):
if arg.parser is not self.parser:
if arg.parser is self.parser:
paths.extend(arg._raw_paths)
elif arg.parser is ntpath:
# GH-103631: Convert separators for backwards compatibility.
# GH-125012: This emits FutureWarning as of Python 3.14.
import warnings
msg = ("pathlib.PurePosixPath(pathlib.PureWindowsPath(...)): "
"converting backward slashes to forward slashes. "
"This will cease in a future Python release. Use "
"PurePosixPath(PureWindowsPath(...).as_posix()) to "
"explicitly convert Windows separators to POSIX "
"separators when 'casting' a Windows-flavoured "
"path object to a POSIX-flavoured path object.")
warnings.warn(msg, FutureWarning, stacklevel=2)
paths.append(arg.as_posix())
else:
paths.extend(arg._raw_paths)
paths.append(str(arg))
else:
try:
path = os.fspath(arg)
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_pathlib/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ def test_as_uri_non_ascii(self):
def test_parse_windows_path(self):
P = self.cls
p = P('c:', 'a', 'b')
pp = P(pathlib.PureWindowsPath('c:\\a\\b'))
with self.assertWarns(FutureWarning):
pp = P(pathlib.PureWindowsPath('c:\\a\\b'))
self.assertEqual(p, pp)

windows_equivalences = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
``pathlib.PurePosixPath(pathlib.PureWindowsPath(...))`` now emits a
:exc:`FutureWarning` indicating that implicit conversion of backward slashes
to forward slashes will cease in a future Python release. Use
``PurePosixPath(PureWindowsPath(...).as_posix())`` to explicitly convert
Windows path separators to POSIX path separators when converting between
path flavours.
Loading