You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pathlib join pure windows path and pure posix path changes it behaviour on 3.13 #125069
Python 3.12.7 (main, Oct 8 2024, 00:39:14) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pathlib; pathlib.PureWindowsPath("C:\\A") / pathlib.PurePosixPath("/foo/C:\\B").relative_to("/")
PureWindowsPath('C:/B')
3.13.0rc3
Python 3.13.0rc3 (main, Oct 7 2024, 23:18:57) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pathlib; pathlib.PureWindowsPath("C:\\A") / pathlib.PurePosixPath("/foo/C:\\B").relative_to("/")
PureWindowsPath('C:/A/foo/C:/B')
Thanks for reporting this! There's a few things going on here. I think it comes down to pathlib's special handling of PurePath(PurePath(...)) and our efforts to delay joining of *pathsegments. I believe the 3.13 behaviour is correct, and that we should fix 3.12. PR coming up...
In the original repro case, the 3.12 behaviour was buggy and the 3.13 behaviour was correct. The optimisation in #111431 (3.13+) happened to fix the issue for paths generated by relative_to(). The change I've applied here should fix the problem at its source.
@barneygale
So, what should I do in my library code? Should I dispatch behaviour by python version? Will the fix lands on 3.12.8 and buggy behaviour still presents in 3.12.0 to 3.12.7 inclusive? 🤔 I want equal behaviour of my function on all supported python versions from 3.8 to 3.13.
@barneygale So, what should I do in my library code? Should I dispatch behaviour by python version? Will the fix lands on 3.12.8 and buggy behaviour still presents in 3.12.0 to 3.12.7 inclusive? 🤔 I want equal behaviour of my function on all supported python versions from 3.8 to 3.13.
Untested, but I think this will work in all version:
diff --git a/src/aioftp/server.py b/src/aioftp/server.py
index 1830d78..d31f40a 100644
--- a/src/aioftp/server.py+++ b/src/aioftp/server.py@@ -1031,7 +1031,7 @@ class Server:
else:
resolved_virtual_path /= part
base_path = connection.user.base_path
- real_path = base_path / resolved_virtual_path.relative_to("/")+ real_path = base_path / str(resolved_virtual_path.relative_to("/"))
# replace with `is_relative_to` check after 3.9+ requirements lands
try:
real_path.relative_to(base_path)
Please use https://discuss.python.org/ for general discussion. If you're looking to convince other people to do work on your behalf (e.g. improving the pathlib codebase) then I suggest you strike a more constructive note. If you're planning to put in your own issues and PRs I'd be happy to review.
Reacted by Peter Bierma, Bénédikt Tran, Savannah Ostrowski, Kirill Podoprigora, Diego Russo, Alex Waygood, Erlend E. Aasland, Hugo van Kemenade, sobolevn, Petro31 and 4 more
Activity
AA-Turner commentedon Oct 7, 2024
cc @barneygale, though the reproducer does look a bit off, with multiple drive roots.
@pohmelie can you reproduce this using only
os.path?A
pohmelie commentedon Oct 7, 2024
@AA-Turner
If you provide a code with
os.pathmodule, then I can test it. But, AFAIK,os.pathhave no ability to manage windows and posix paths.terryjreedy commentedon Oct 7, 2024
Checking 3.13 What's New or the linked log file might reveal if intentional change.
imfeh2 commentedon Oct 8, 2024
It happens after this change.
#111431
ZeroIntensity commentedon Oct 8, 2024
cc @barneygale, apparently that PR introduced a breaking change.
Edit: oh wait, Adam already pinged, sorry!
barneygale commentedon Oct 8, 2024
Thanks for reporting this! There's a few things going on here. I think it comes down to pathlib's special handling of
PurePath(PurePath(...))and our efforts to delay joining of*pathsegments. I believe the 3.13 behaviour is correct, and that we should fix 3.12. PR coming up...barneygale commentedon Oct 8, 2024
Another repro, this one works in 3.13 and 3.14:
pythonGH-125069: Fix inconsistent joining in `WindowsPath(PosixPath(.…
Merge branch 'main' into pythongh-125069
barneygale commentedon Oct 13, 2024
PR available, if anyone has a mo to review: #125156
Merge branch 'main' into pythongh-125069
GH-125069: Fix inconsistent joining in `WindowsPath(PosixPath(...))` (#…
pythonGH-125069: Fix inconsistent joining in `WindowsPath(PosixPath(.…
[3.12] pythonGH-125069: Fix inconsistent joining in `WindowsPath(Posi…
[3.13] GH-125069: Fix inconsistent joining in `WindowsPath(PosixPath(…
[3.12] GH-125069: Fix inconsistent joining in `WindowsPath(PosixPath(…
barneygale commentedon Oct 13, 2024
I've pushed a fix to 3.12, 3.13 and 3.14 (main).
In the original repro case, the 3.12 behaviour was buggy and the 3.13 behaviour was correct. The optimisation in #111431 (3.13+) happened to fix the issue for paths generated by
relative_to(). The change I've applied here should fix the problem at its source.Thanks for reporting :)
pohmelie commentedon Oct 13, 2024
@barneygale
So, what should I do in my library code? Should I dispatch behaviour by python version? Will the fix lands on 3.12.8 and buggy behaviour still presents in 3.12.0 to 3.12.7 inclusive? 🤔 I want equal behaviour of my function on all supported python versions from 3.8 to 3.13.
barneygale commentedon Oct 13, 2024
Untested, but I think this will work in all version:
barneygale commentedon Oct 14, 2024
Please use https://discuss.python.org/ for general discussion. If you're looking to convince other people to do work on your behalf (e.g. improving the pathlib codebase) then I suggest you strike a more constructive note. If you're planning to put in your own issues and PRs I'd be happy to review.
pohmelie commentedon Oct 14, 2024
@barneygale yep, looks like this
str(...)trick works, thank you!force conversion to avoid buggy pathlib implementation for old python…
barneygale commentedon Oct 14, 2024
Wow what valuable feedback, thanks buddy! :P