Describe the bug
Yarl supports a much wider definition of query parameters, including sequences of strings. I have to ignore lines that pass those more sophisticated types to the aiohttp calls.
To Reproduce
hosts = ["a", "b"]
async with ClientSession() as client:
resp = await client.get(
"https://api.example.com/",
params={"hosts": hosts},
)
This causes a type error, but works perfectly well at runtime.
$ python3
Python 3.11.8 (main, Mar 8 2024, 09:32:16) [GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import yarl
>>> yarl.URL( "https://api.example.com/").update_query({"hosts": ["a", "b"]})
URL('https://api.example.com/?hosts=a&hosts=b')
Expected behavior
I expect that the type signature for params in aiohttp matches the type signature in yarl.update_query.
Logs/tracebacks
/home/lpetre/dev/provision.py
/home/lpetre/dev/provision.py:65:42 - error: Argument of type "dict[str, list[str] | str]" cannot be assigned to parameter "params" of type "Mapping[str, str] | None" in function "get"
Type "dict[str, list[str] | str]" is incompatible with type "Mapping[str, str] | None"
"dict[str, list[str] | str]" is incompatible with "Mapping[str, str]"
Type parameter "_VT_co@Mapping" is covariant, but "list[str] | str" is not a subtype of "str"
Type "list[str] | str" is incompatible with type "str"
"list[str]" is incompatible with "str"
"dict[str, list[str] | str]" is incompatible with "None" (reportArgumentType)
Python Version
$ python --version
Python 3.11.8
aiohttp Version
$ python -m pip show aiohttp
Name: aiohttp
Version: 3.9.5
Summary: Async http client/server framework (asyncio)
Home-page: https://github.com/aio-libs/aiohttp
Author:
Author-email:
License: Apache 2
Location: /home/lpetre/dev/src/github.com/midjourney/image-generation/.venv/lib/python3.11/site-packages
Requires: aiosignal, attrs, frozenlist, multidict, yarl
Required-by: gcsfs
multidict Version
$ python -m pip show multidict
Name: multidict
Version: 6.0.5
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: /home/lpetre/dev/src/github.com/midjourney/image-generation/.venv/lib/python3.11/site-packages
Requires:
Required-by: aiohttp, yarl
yarl Version
$ python -m pip show yarl
Name: yarl
Version: 1.9.4
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache-2.0
Location: /home/lpetre/dev/src/github.com/midjourney/image-generation/.venv/lib/python3.11/site-packages
Requires: idna, multidict
OS
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
Related component
Client
Additional context
No response
Code of Conduct
Describe the bug
Yarl supports a much wider definition of query parameters, including sequences of strings. I have to ignore lines that pass those more sophisticated types to the aiohttp calls.
To Reproduce
This causes a type error, but works perfectly well at runtime.
Expected behavior
I expect that the type signature for params in aiohttp matches the type signature in yarl.update_query.
Logs/tracebacks
/home/lpetre/dev/provision.py /home/lpetre/dev/provision.py:65:42 - error: Argument of type "dict[str, list[str] | str]" cannot be assigned to parameter "params" of type "Mapping[str, str] | None" in function "get" Type "dict[str, list[str] | str]" is incompatible with type "Mapping[str, str] | None" "dict[str, list[str] | str]" is incompatible with "Mapping[str, str]" Type parameter "_VT_co@Mapping" is covariant, but "list[str] | str" is not a subtype of "str" Type "list[str] | str" is incompatible with type "str" "list[str]" is incompatible with "str" "dict[str, list[str] | str]" is incompatible with "None" (reportArgumentType)Python Version
aiohttp Version
multidict Version
yarl Version
OS
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
Related component
Client
Additional context
No response
Code of Conduct