diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index 62dc6feffc6..85914df4eb4 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -22,6 +22,7 @@ class TypeHintMatch: function_name: str return_type: list[str] | str | None | object arg_types: dict[int, str] | None = None + kwargs_type: str | None = None check_return_type_inheritance: bool = False @@ -613,7 +614,7 @@ class HassTypeHintChecker(BaseChecker): # type: ignore[misc] priority = -1 msgs = { "W7431": ( - "Argument %d should be of type %s", + "Argument %s should be of type %s", "hass-argument-type", "Used when method argument type is incorrect", ), @@ -709,6 +710,16 @@ class HassTypeHintChecker(BaseChecker): # type: ignore[misc] args=(key + 1, expected_type), ) + # Check that kwargs is correctly annotated. + if match.kwargs_type and not _is_valid_type( + match.kwargs_type, node.args.kwargannotation + ): + self.add_message( + "hass-argument-type", + node=node, + args=(node.args.kwarg, match.kwargs_type), + ) + # Check the return type. if not _is_valid_return_type(match, node.returns): self.add_message(