Skip to content

Commit 0b82655

Browse files
authored
[PR #9083/a6dd415 backport][3.10] Remove unused backwards compatibility code for old yarl versions (#9289)
1 parent 2a92a5c commit 0b82655

File tree

3 files changed

+10
-40
lines changed

3 files changed

+10
-40
lines changed

aiohttp/client_reqrep.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import attr
2929
from multidict import CIMultiDict, CIMultiDictProxy, MultiDict, MultiDictProxy
30-
from yarl import URL, __version__ as yarl_version
30+
from yarl import URL
3131

3232
from . import hdrs, helpers, http, multipart, payload
3333
from .abc import AbstractStreamWriter
@@ -89,7 +89,6 @@
8989

9090

9191
_CONTAINS_CONTROL_CHAR_RE = re.compile(r"[^-!#$%&'*+.^_`|~0-9a-zA-Z]")
92-
_YARL_SUPPORTS_EXTEND_QUERY = tuple(map(int, yarl_version.split(".")[:2])) >= (1, 11)
9392
json_re = re.compile(r"^application/(?:[\w.+-]+?\+)?json")
9493

9594

@@ -303,13 +302,7 @@ def __init__(
303302
# assert session is not None
304303
self._session = cast("ClientSession", session)
305304
if params:
306-
if _YARL_SUPPORTS_EXTEND_QUERY:
307-
url = url.extend_query(params)
308-
else:
309-
q = MultiDict(url.query)
310-
url2 = url.with_query(params)
311-
q.extend(url2.query)
312-
url = url.with_query(q)
305+
url = url.extend_query(params)
313306
self.original_url = url
314307
self.url = url.with_fragment(None)
315308
self.method = method.upper()

aiohttp/typedefs.py

+1-12
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,12 @@
88
Iterable,
99
Mapping,
1010
Protocol,
11-
Sequence,
1211
Tuple,
1312
Union,
1413
)
1514

1615
from multidict import CIMultiDict, CIMultiDictProxy, MultiDict, MultiDictProxy, istr
17-
from yarl import URL
18-
19-
try:
20-
# Available in yarl>=1.10.0
21-
from yarl import Query as _Query
22-
except ImportError: # pragma: no cover
23-
SimpleQuery = Union[str, int, float] # pragma: no cover
24-
QueryVariable = Union[SimpleQuery, "Sequence[SimpleQuery]"] # pragma: no cover
25-
_Query = Union[ # type: ignore[misc] # pragma: no cover
26-
None, str, "Mapping[str, QueryVariable]", "Sequence[Tuple[str, QueryVariable]]"
27-
]
16+
from yarl import URL, Query as _Query
2817

2918
Query = _Query
3019

tests/test_client_functional.py

+7-19
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from yarl import URL
2121

2222
import aiohttp
23-
from aiohttp import Fingerprint, ServerFingerprintMismatch, client_reqrep, hdrs, web
23+
from aiohttp import Fingerprint, ServerFingerprintMismatch, hdrs, web
2424
from aiohttp.abc import AbstractResolver
2525
from aiohttp.client_exceptions import (
2626
ClientResponseError,
@@ -676,10 +676,7 @@ async def handler(request):
676676
assert 200 == resp.status
677677

678678

679-
@pytest.mark.parametrize("yarl_supports_extend_query", [True, False])
680-
async def test_params_and_query_string(
681-
aiohttp_client: AiohttpClient, yarl_supports_extend_query: bool
682-
) -> None:
679+
async def test_params_and_query_string(aiohttp_client: AiohttpClient) -> None:
683680
"""Test combining params with an existing query_string."""
684681

685682
async def handler(request: web.Request) -> web.Response:
@@ -690,18 +687,13 @@ async def handler(request: web.Request) -> web.Response:
690687
app.router.add_route("GET", "/", handler)
691688
client = await aiohttp_client(app)
692689

693-
# Ensure the old path is tested for old yarl versions
694-
with mock.patch.object(
695-
client_reqrep, "_YARL_SUPPORTS_EXTEND_QUERY", yarl_supports_extend_query
696-
):
697-
async with client.get("/?q=abc", params="q=test&d=dog") as resp:
698-
assert resp.status == 200
690+
async with client.get("/?q=abc", params="q=test&d=dog") as resp:
691+
assert resp.status == 200
699692

700693

701694
@pytest.mark.parametrize("params", [None, "", {}, MultiDict()])
702-
@pytest.mark.parametrize("yarl_supports_extend_query", [True, False])
703695
async def test_empty_params_and_query_string(
704-
aiohttp_client: AiohttpClient, params: Any, yarl_supports_extend_query: bool
696+
aiohttp_client: AiohttpClient, params: Any
705697
) -> None:
706698
"""Test combining empty params with an existing query_string."""
707699

@@ -713,12 +705,8 @@ async def handler(request: web.Request) -> web.Response:
713705
app.router.add_route("GET", "/", handler)
714706
client = await aiohttp_client(app)
715707

716-
# Ensure the old path is tested for old yarl versions
717-
with mock.patch.object(
718-
client_reqrep, "_YARL_SUPPORTS_EXTEND_QUERY", yarl_supports_extend_query
719-
):
720-
async with client.get("/?q=abc", params=params) as resp:
721-
assert resp.status == 200
708+
async with client.get("/?q=abc", params=params) as resp:
709+
assert resp.status == 200
722710

723711

724712
async def test_drop_params_on_redirect(aiohttp_client: AiohttpClient) -> None:

0 commit comments

Comments
 (0)