Skip to content

Commit

Permalink
Revert "Revert "Remove unused backwards compatibility code for old ya…
Browse files Browse the repository at this point in the history
…rl versions (#9083)""

This reverts commit 0237dbe.
  • Loading branch information
bdraco committed Sep 23, 2024
1 parent c842bd4 commit 7b41d4e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 40 deletions.
11 changes: 2 additions & 9 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
)

from multidict import CIMultiDict, CIMultiDictProxy, MultiDict, MultiDictProxy
from yarl import URL, __version__ as yarl_version
from yarl import URL

from . import hdrs, helpers, http, multipart, payload
from .abc import AbstractStreamWriter
Expand Down Expand Up @@ -91,7 +91,6 @@


_CONTAINS_CONTROL_CHAR_RE = re.compile(r"[^-!#$%&'*+.^_`|~0-9a-zA-Z]")
_YARL_SUPPORTS_EXTEND_QUERY = tuple(map(int, yarl_version.split(".")[:2])) >= (1, 11)


def _gen_default_accept_encoding() -> str:
Expand Down Expand Up @@ -231,13 +230,7 @@ def __init__(
# assert session is not None
self._session = cast("ClientSession", session)
if params:
if _YARL_SUPPORTS_EXTEND_QUERY:
url = url.extend_query(params)
else:
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()
Expand Down
13 changes: 1 addition & 12 deletions aiohttp/typedefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,12 @@
Iterable,
Mapping,
Protocol,
Sequence,
Tuple,
Union,
)

from multidict import CIMultiDict, CIMultiDictProxy, MultiDict, MultiDictProxy, istr
from yarl import URL

try:
# Available in yarl>=1.10.0
from yarl import Query as _Query
except ImportError: # pragma: no cover
SimpleQuery = Union[str, int, float] # pragma: no cover
QueryVariable = Union[SimpleQuery, "Sequence[SimpleQuery]"] # pragma: no cover
_Query = Union[ # type: ignore[misc] # pragma: no cover
None, str, "Mapping[str, QueryVariable]", "Sequence[Tuple[str, QueryVariable]]"
]
from yarl import URL, Query as _Query

Query = _Query

Expand Down
26 changes: 7 additions & 19 deletions tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from yarl import URL

import aiohttp
from aiohttp import Fingerprint, ServerFingerprintMismatch, client_reqrep, hdrs, web
from aiohttp import Fingerprint, ServerFingerprintMismatch, hdrs, web
from aiohttp.abc import AbstractResolver, ResolveResult
from aiohttp.client_exceptions import (
ClientResponseError,
Expand Down Expand Up @@ -706,10 +706,7 @@ async def handler(request: web.Request) -> web.Response:
assert 200 == resp.status


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

async def handler(request: web.Request) -> web.Response:
Expand All @@ -720,18 +717,13 @@ async def handler(request: web.Request) -> web.Response:
app.router.add_route("GET", "/", handler)
client = await aiohttp_client(app)

# Ensure the old path is tested for old yarl versions
with mock.patch.object(
client_reqrep, "_YARL_SUPPORTS_EXTEND_QUERY", yarl_supports_extend_query
):
async with client.get("/?q=abc", params="q=test&d=dog") as resp:
assert resp.status == 200
async with client.get("/?q=abc", params="q=test&d=dog") as resp:
assert resp.status == 200


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

Expand All @@ -743,12 +735,8 @@ async def handler(request: web.Request) -> web.Response:
app.router.add_route("GET", "/", handler)
client = await aiohttp_client(app)

# Ensure the old path is tested for old yarl versions
with mock.patch.object(
client_reqrep, "_YARL_SUPPORTS_EXTEND_QUERY", yarl_supports_extend_query
):
async with client.get("/?q=abc", params=params) as resp:
assert resp.status == 200
async with client.get("/?q=abc", params=params) as resp:
assert resp.status == 200


async def test_drop_params_on_redirect(aiohttp_client: AiohttpClient) -> None:
Expand Down

0 comments on commit 7b41d4e

Please sign in to comment.