-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Pathlib join pure windows path and pure posix path changes it behaviour on 3.13 #125069
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
Comments
cc @barneygale, though the reproducer does look a bit off, with multiple drive roots. @pohmelie can you reproduce this using only A |
@AA-Turner |
Checking 3.13 What's New or the linked log file might reveal if intentional change. |
It happens after this change. |
Classic that an optimization changes semantics. I'd rip out that optimization or make sure that the new behavior matches the specification. |
cc @barneygale, apparently that PR introduced a breaking change. Edit: oh wait, Adam already pinged, sorry! |
Thanks for reporting this! There's a few things going on here. I think it comes down to pathlib's special handling of |
Another repro, this one works in 3.13 and 3.14: >>> a = PureWindowsPath('a')
>>> b1 = PurePosixPath('b', 'c:\\d')
>>> b2 = PurePosixPath('b/c:\\d')
>>> b1 == b2
True
>>> a / b1
PureWindowsPath('c:/d')
>>> a / b2
PureWindowsPath('a/b/c:/d') |
…..))` `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.
PR available, if anyone has a mo to review: #125156 |
…125156) `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. Co-authored-by: Bénédikt Tran <[email protected]>
…..))` (pythonGH-125156) `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 cb8e599) Co-authored-by: Barney Gale <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
…xPath(...))` (pythonGH-125156) `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. Co-authored-by: Bénédikt Tran <[email protected]>. (cherry picked from commit cb8e599) Co-authored-by: Barney Gale <[email protected]>
…...))` (GH-125156) (#125409) `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 cb8e599) Co-authored-by: Barney Gale <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
…...))` (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 cb8e599) Co-authored-by: Bénédikt Tran <[email protected]>
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 Thanks for reporting :) |
@barneygale |
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) |
(Pathlib code is atrocious, btw. ) (I think for something as big as Python, getting rid of informal specifications would be a good idea, but I doubt the people in the project could ever accept it. The specification of many pathlib functions is completely underspecified.) |
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. |
@barneygale yep, looks like this |
I don't particularly care that much about Python. I looked at the code for this issue and I just wanted to leave my opinion on the Internet, which could be used by someone as an argument to fix pathlib. I was just being nice in sharing my (highly valuable) opinion. I don't particularly care if anyone does something with it. I certainly am not forcing anyone to do anything. Not sure where you got that idea. I am also not interested in discussion, because that would suggest I care about the opinion of others, which I don't, since I already am an expert. So, ignore my advice all you want, but that doesn't change the reality of the quality of that code. The code generator is even worse, for those interested. I will say it again: I am not asking for your opinion. I am giving you mine. |
Wow what valuable feedback, thanks buddy! :P |
Uh oh!
There was an error while loading. Please reload this page.
Bug report
Bug description:
3.12.7
3.13.0rc3
Not sure if it is a bug, or a fixed behaviour
CPython versions tested on:
3.12, 3.13
Operating systems tested on:
Linux
Linked PRs
WindowsPath(PosixPath(...))
#125156WindowsPath(PosixPath(...))
(GH-125156) #125409WindowsPath(PosixPath(...))
(GH-125156) #125410The text was updated successfully, but these errors were encountered: