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

Remove unused backwards compatibility code for old yarl versions #9083

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (
InvalidURL,
Expand Down Expand Up @@ -702,10 +702,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 @@ -716,18 +713,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 @@ -739,12 +731,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
Loading