Uh oh!
There was an error while loading. Please reload this page.
gh-67041: Allow to distinguish between empty and not defined URI components - #123305
Conversation
…I components Changes in the urllib.parse module: * Add option allow_none in urlparse(), urlsplit() and urldefrag(). If it is true, represent not defined components as None instead of an empty string. * Add option keep_empty in urlunparse() and urlunsplit(). If it is true, keep empty non-None components in the resulting string. * Add option keep_empty in the geturl() method of DefragResult, SplitResult, ParseResult and the corresponding bytes counterparts.
7032015 to
a60c9beCompareserhiy-storchaka
commented
Nov 27, 2024
It is now ready to review. The status of Unfortunately, these objects now have The long term plan is to make |
serhiy-storchaka
commented
Dec 5, 2024
I am sorry, I forget to copy the @orsenthil, @barneygale, could you please make a review? |
I think that Possible alternatives:
|
serhiy-storchaka
commented
Nov 17, 2025
Maybe |
merwok
commented
Nov 17, 2025
I think it should be To change the default in the future, do you plan on adding a warning first? |
serhiy-storchaka
commented
Nov 17, 2025
On one hand, a warning will inform everyone about the change (it should be a FutureWarning). You will have to pass explicit True or False to silence it and get your behavior. This how we normally do. On other hand, the warning will unnecessary disturb those who are fine with any behavior. We will discuss this when the time come. |
serhiy-storchaka
commented
Nov 17, 2025
Currently, missing and empty component are not distinguishable. This parameter will allow to distinguish them. This PR adds also the |
merwok
commented
Nov 17, 2025
Ah your’re right, there is empty component and empty string.
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Looks like we maintain a patch for the iOS build which is failing to apply with this PR. |
orsenthil
commented
Jan 22, 2026
This file https://github.com/python/cpython/blob/main/Mac/Resources/app-store-compliance.patch (a meta-patch) needs to be updated for the new behavior (returning None instead of '') for it apply cleanly. |
This file https://github.com/python/cpython/blob/main/Mac/Resources/app-store-compliance.patch should be updated with this content. And patch application is successful. And was successful with this change. |
…none' into urllib-parse-allow-none
…/cpython into urllib-parse-allow-none
serhiy-storchaka
commented
Jan 22, 2026
Thank you @orsenthil. I was confused by this failure. The original issue is interesting: #120522. |
Uh oh!
There was an error while loading. Please reload this page.
…I components (pythonGH-123305) Changes in the urllib.parse module: * Add option missing_as_none in urlparse(), urlsplit() and urldefrag(). If it is true, represent not defined components as None instead of an empty string. * Add option keep_empty in urlunparse() and urlunsplit(). If it is true, keep empty non-None components in the resulting string.
Changes in the
urllib.parsemodule:allow_nonemissing_as_none inurlparse(),urlsplit()andurldefrag(). If it is true, represent not defined components as None instead of an empty string.urlunparse()andurlunsplit(). If it is true, keep empty non-None components in the resulting string. By default it is the same as the allow_none value for the result of theurlparse()andurlsplit()calls.Add option keep_empty in thegeturl()method ofDefragResult,SplitResult,ParseResultand the corresponding bytes counterparts.