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

Incorrect "suspect signature type" with dictionary unpacking #2176

Open
Ten0 opened this issue Dec 11, 2024 · 0 comments
Open

Incorrect "suspect signature type" with dictionary unpacking #2176

Ten0 opened this issue Dec 11, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Ten0
Copy link

Ten0 commented Dec 11, 2024

What happened?

if len(sig.parameters) != callback_args[type]["count"]:
self.logger.warning(
"Suspect incorrect signature type for callback %s() in %s, should be %s - discarding",
funcref.__name__,
name,
callback_args[type]["signature"][use_dictionary_unpacking],
)
fails to gracefully expand arguments of kwargs with dictionary unpacking.

Version

4.4.2

Installation type

Home Assistant add-on

Relevant log output

WARNING AppDaemon: Suspect incorrect signature type for callback on_motion_detected() in my_app, should be f(self, entity, attribute, old, new, **kwargs) - discarding

Relevant code in the app or config file that caused the issue

use_dictionary_unpacking: true
import appdaemon.plugins.hass.hassapi as hass


class MyApp(hass.Hass):

    def initialize(self):
        self.listen_state(
            self.on_motion_detected,
            "binary_sensor.name",
            new="on",
			abc=3
        )

    def on_motion_detected(self, entity, attribute, old, new, abc):
        self.log("Motion!")

Anything else?

It looks like this code could be smarter when use_dictionary_unpacking is involved.
**kwargs is indeed more pythonic to the extent that we can use it for what it's meant for, that is, creating functions that take this dynamic list of arguments and expand them right away.

@Ten0 Ten0 added the bug Something isn't working label Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant