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

[PR #8564/b543677e backport][3.11] Use Query typedef from yarl for params #9081

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
1 change: 1 addition & 0 deletions CHANGES/8564.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved type on ``params`` to match the underlying type allowed by ``yarl`` -- by :user:`lpetre`.
12 changes: 6 additions & 6 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
from .http_websocket import WSHandshakeError, WSMessage, ws_ext_gen, ws_ext_parse
from .streams import FlowControlDataQueue
from .tracing import Trace, TraceConfig
from .typedefs import JSONEncoder, LooseCookies, LooseHeaders, StrOrURL
from .typedefs import JSONEncoder, LooseCookies, LooseHeaders, Query, StrOrURL

__all__ = (
# client_exceptions
Expand Down Expand Up @@ -161,7 +161,7 @@


class _RequestOptions(TypedDict, total=False):
params: Union[Mapping[str, Union[str, int]], str, None]
params: Query
data: Any
json: Any
cookies: Union[LooseCookies, None]
Expand Down Expand Up @@ -455,7 +455,7 @@ async def _request(
method: str,
str_or_url: StrOrURL,
*,
params: Optional[Mapping[str, str]] = None,
params: Query = None,
data: Any = None,
json: Any = None,
cookies: Optional[LooseCookies] = None,
Expand Down Expand Up @@ -835,7 +835,7 @@ def ws_connect(
heartbeat: Optional[float] = None,
auth: Optional[BasicAuth] = None,
origin: Optional[str] = None,
params: Optional[Mapping[str, str]] = None,
params: Query = None,
headers: Optional[LooseHeaders] = None,
proxy: Optional[StrOrURL] = None,
proxy_auth: Optional[BasicAuth] = None,
Expand Down Expand Up @@ -887,7 +887,7 @@ async def _ws_connect(
heartbeat: Optional[float] = None,
auth: Optional[BasicAuth] = None,
origin: Optional[str] = None,
params: Optional[Mapping[str, str]] = None,
params: Query = None,
headers: Optional[LooseHeaders] = None,
proxy: Optional[StrOrURL] = None,
proxy_auth: Optional[BasicAuth] = None,
Expand Down Expand Up @@ -1452,7 +1452,7 @@ def request(
method: str,
url: StrOrURL,
*,
params: Optional[Mapping[str, str]] = None,
params: Query = None,
data: Any = None,
json: Any = None,
headers: Optional[LooseHeaders] = None,
Expand Down
3 changes: 2 additions & 1 deletion aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
JSONDecoder,
LooseCookies,
LooseHeaders,
Query,
RawHeaders,
)

Expand Down Expand Up @@ -262,7 +263,7 @@ def __init__(
method: str,
url: URL,
*,
params: Optional[Mapping[str, str]] = None,
params: Query = None,
headers: Optional[LooseHeaders] = None,
skip_auto_headers: Optional[Iterable[str]] = None,
data: Any = None,
Expand Down
13 changes: 13 additions & 0 deletions aiohttp/typedefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,26 @@
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]]"
]

Query = _Query

DEFAULT_JSON_ENCODER = json.dumps
DEFAULT_JSON_DECODER = json.loads

Expand Down
Loading