Skip to content
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

Add extend_query method #1128

Merged
merged 30 commits into from
Sep 8, 2024
Merged

Add extend_query method #1128

merged 30 commits into from
Sep 8, 2024

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Sep 8, 2024

What do these changes do?

Adds a new method called extend_query that will add additional keys instead of replacing them like update_query. The goal is to replace the hand rolled version in aiohttp

Are there changes in behavior for the user?

no

Related issue number

#1127

yarl/_url.py Dismissed Show dismissed Hide dismissed
yarl/_url.py Dismissed Show dismissed Hide dismissed
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Sep 8, 2024
Copy link

codecov bot commented Sep 8, 2024

Codecov Report

Attention: Patch coverage is 98.41270% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.20%. Comparing base (48bdc87) to head (d1baa7f).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
tests/test_update_query.py 97.95% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1128      +/-   ##
==========================================
+ Coverage   95.15%   95.20%   +0.04%     
==========================================
  Files          30       30              
  Lines        4646     4709      +63     
  Branches      411      417       +6     
==========================================
+ Hits         4421     4483      +62     
- Misses        199      200       +1     
  Partials       26       26              
Flag Coverage Δ
CI-GHA 95.15% <98.41%> (+0.04%) ⬆️
MyPy 40.78% <19.04%> (-0.32%) ⬇️
OS-Linux 99.39% <100.00%> (+<0.01%) ⬆️
OS-Windows 99.48% <100.00%> (+<0.01%) ⬆️
OS-macOS 99.09% <100.00%> (+0.01%) ⬆️
Py-3.10.11 98.99% <100.00%> (+0.01%) ⬆️
Py-3.10.14 99.23% <100.00%> (+0.01%) ⬆️
Py-3.11.9 99.23% <100.00%> (+0.01%) ⬆️
Py-3.12.5 99.23% <100.00%> (+0.01%) ⬆️
Py-3.13.0-rc.1 99.23% <100.00%> (+0.01%) ⬆️
Py-3.8.10 98.94% <100.00%> (+0.01%) ⬆️
Py-3.8.18 99.17% <100.00%> (+0.01%) ⬆️
Py-3.9.13 98.94% <100.00%> (+0.01%) ⬆️
Py-3.9.19 99.17% <100.00%> (+0.01%) ⬆️
Py-pypy7.3.11 99.23% <100.00%> (+0.01%) ⬆️
Py-pypy7.3.16 99.23% <100.00%> (+0.01%) ⬆️
Py-pypy7.3.17 99.26% <100.00%> (+0.01%) ⬆️
VM-macos-latest 99.09% <100.00%> (+0.01%) ⬆️
VM-ubuntu-latest 99.39% <100.00%> (+<0.01%) ⬆️
VM-windows-latest 99.48% <100.00%> (+<0.01%) ⬆️
pytest 99.39% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bdraco
Copy link
Member Author

bdraco commented Sep 8, 2024

Verified this works as expected in aiohttp with this change

diff --git a/aiohttp/client_reqrep.py b/aiohttp/client_reqrep.py
index 6eaba561b..6e0f76a2e 100644
--- a/aiohttp/client_reqrep.py
+++ b/aiohttp/client_reqrep.py
@@ -229,10 +229,7 @@ class ClientRequest:
         # assert session is not None
         self._session = cast("ClientSession", session)
         if params:
-            q = MultiDict(url.query)
-            url2 = url.with_query(params)
-            q.extend(url2.query)
-            url = url.with_query(q)
+            url = url.extend_query(params)
         self.original_url = url
         self.url = url.with_fragment(None)
         self.method = method.upper()

@bdraco
Copy link
Member Author

bdraco commented Sep 8, 2024

Doing a bit of production testing before merge. If that all goes well, I'll bump the version, do a release and than open a PR to aiohttp to replace the hand rolled method

yarl/_url.py Outdated Show resolved Hide resolved
@bdraco
Copy link
Member Author

bdraco commented Sep 8, 2024

In turns out I didn't need to split update_query so I can split this PR up a bit

yarl/_url.py Outdated Show resolved Hide resolved
yarl/_url.py Outdated Show resolved Hide resolved
bdraco added a commit that referenced this pull request Sep 8, 2024
docs/api.rst Outdated Show resolved Hide resolved
yarl/_url.py Show resolved Hide resolved
yarl/_url.py Outdated Show resolved Hide resolved
@bdraco bdraco marked this pull request as ready for review September 8, 2024 20:47
@bdraco bdraco merged commit 80e5740 into master Sep 8, 2024
47 of 49 checks passed
@bdraco bdraco deleted the extend_query branch September 8, 2024 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant