-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Adjust path_to_url et al. to produce the same results on Python 3.14+ #13423
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
hroncok
wants to merge
1
commit into
pypa:main
Choose a base branch
from
hroncok:python3.14
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix remaining test failures in Python 3.14 by adjusting ``path_to_url`` and similar functions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not proud of this :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't obvious to me how else to do this either 🙁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there something in cpython we can reference here so people reading this later knows what’s going on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can try digging a reference to the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, if we could find something that explained why cpython changed what they did, and why the new result is "correct" and why pip needs something different from the "correct" answer, that would be best (as it would give us a much better basis for informed decisions if this code ever needs to change again).
Unfortunately, I get the impression that there's no real "correct" answer here, and the cpython change was "because it's more consistent with (something or other that pip maybe doesn't even care about)". If so, then documenting what precisely pip is using to base its idea of what "the url for a pathname" is, would be better than nothing.
Worst case scenario would be that there's simply no standard for how to convert a pathname to a URL in general, and it's all just a mess of guesswork and hacks 🙁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll list the URLs with
file:
prefixes so it's a little easier to grok:file:foo
- relative pathfile:///foo
- absolute path (POSIX), path beginning with single slash (Windows)file:///c:/foo
- DOS drive path (Windows)file://server/foo
- UNC path (Windows)In 3.14 it should do, yeah. Acceptable slash-prefix variants:
file:/foo
- absolute path (POSIX), path beginning with single slash (Windows)file:c:/foo
,file:/c:/foo
- DOS drive path (Windows)file:////server/foo
,file://///server/foo
- UNC path (Windows)Windows DOS paths also support a pipe (
|
) rather than a colon after the drive letter.The authority can also vary for non-UNC paths.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be accepted in the latest versions of 3.12 and 3.13 (see list of backported changes), but in older versions they're mishandled.
The major 3.14-only change here is that
pathname2url('/tmp')
now returns'///tmp'
, whereas in 3.13 it returns'/tmp'
. Otherwise it's a similar story tourl2pathname
above - the latest bugfix releases of 3.13 and 3.12 are fine, but older maintenance releases (and anything before 3.12) is buggyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you share examples of where this isn't the case? Paths should roundtrip
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm getting confused. The pip code is
which I misread as path -> URL -> path. So I couldn't see why that wasn't (effectively) a null operation. But it's not, it's the other way around, making it (in effect) a URL normalisation operation.
If that's the case, my understanding of what's going on has definitely been helped by this discussion, because I couldn't have said that before1. But I'm now left with another question, which is why, if we're returning a normalised URL (with the
file:
prefix omitted), we even care about the extra 2 slashes. I feel like we're either doing some incorrect parsing on the returned URL, or we're (incorrectly) treating it as a path rather than a schemeless URL somewhere 🙁Or, to put this another way, I think that removing the
//
is simply patching over a more significant bug in our handling of the return value from this function, and we should be looking for that bug, rather than trying to undo the changes CPython made.Of course, there's also a "practicality beats purity" question here - if this means pip doesn't work on Python 3.14, we might need to make the expedient choice in order to get a fix into pip 25.2, which is the release that will end up in Python 3.14, and will be the current release when 3.14 is released.
Footnotes
We should definitely include a comment above that code saying that it's normalising the provided URL. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think our motivating care is that the tests no longer pass. Pip is not apparently broken on the Python 3.14 betas.
So it's a question of modifying the function to keep the behavior consistent across Python versions, or modifying the tests, and the later requires significantly more confidence about what the right behavior is.