mypy / error: Missing named argument ... [call-arg] / for optional kwargs
JPHutchins opened this issue · comments
- bleak version: 0.21.1
- Python version: 3.10, 3.12
- Operating System: Ubuntu 22.04, Windows 11
- BlueZ version (
bluetoothctl -v
) in case of Linux: NA
Description
Mypy treats kwargs that are Unpack
ed as required. In fact, these kwargs were always intended as platform-specific optional arguments.
Mypy will diagnose missing kwargs as errors. In bleak, this occurs for any function that types kwargs as Unpack[ExtraArgs]
. These include the methods discover, find_device_by_address, find_device_by_name, and find_device_by_filter.
Where a more friendly solution may be to use Generic
and type aliases, use of Unpack
is a welcome improvement over kwargs, so I believe that it's simple enough to add total=False because ALL of the kwargs are optional. Refer to https://peps.python.org/pep-0692/#required-and-non-required-keys. If finer grained control is required, then I suggest Generic and Type Aliases so that the user can see the arguments in their editor instead of having to rely on documentation.
What I Did
Ran mypy 1.7.1 on a file like:
from bleak import BleakScanner
async def main() -> None:
await BleakScanner.find_device_by_address("address")
mypy .
will diagnose every missing kwarg as error:
smpclient\blah.py:5: error: Missing named argument "service_uuids" for "find_device_by_address" of "BleakScanner" [call-arg]
smpclient\blah.py:5: error: Missing named argument "scanning_mode" for "find_device_by_address" of "BleakScanner" [call-arg]
smpclient\blah.py:5: error: Missing named argument "bluez" for "find_device_by_address" of "BleakScanner" [call-arg]
smpclient\blah.py:5: error: Missing named argument "cb" for "find_device_by_address" of "BleakScanner" [call-arg]
smpclient\blah.py:5: error: Missing named argument "backend" for "find_device_by_address" of "BleakScanner" [call-arg]
Logs
N/A
poetry run mypy .
within the bleak repo generates errors, and bleak does not enforce mypy, so it makes sense that this would only be noticed downstream.