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

mypy / error: Missing named argument ... [call-arg] / for optional kwargs #1487

Closed
JPHutchins opened this issue Dec 30, 2023 · 1 comment · Fixed by #1488
Closed

mypy / error: Missing named argument ... [call-arg] / for optional kwargs #1487

JPHutchins opened this issue Dec 30, 2023 · 1 comment · Fixed by #1488

Comments

@JPHutchins
Copy link
Contributor

  • 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 Unpacked 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

@JPHutchins
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants