diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index 82118209e65..4b22d1284d7 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -3425,6 +3425,14 @@ class HassTypeHintChecker(BaseChecker): # Check that all positional arguments are correctly annotated. if match.arg_types: for key, expected_type in match.arg_types.items(): + if key > len(node.args.args) - 1: + # The number of arguments is less than expected + self.add_message( + "hass-argument-type", + node=node, + args=(key + 1, expected_type, node.name), + ) + continue if node.args.args[key].name in _COMMON_ARGUMENTS: # It has already been checked, avoid double-message continue diff --git a/tests/pylint/test_enforce_type_hints.py b/tests/pylint/test_enforce_type_hints.py index 41605bf2f2b..fac9cf0785c 100644 --- a/tests/pylint/test_enforce_type_hints.py +++ b/tests/pylint/test_enforce_type_hints.py @@ -1497,3 +1497,39 @@ def test_invalid_generic( ), ): type_hint_checker.visit_asyncfunctiondef(func_node) + + +def test_missing_argument( + linter: UnittestLinter, + type_hint_checker: BaseChecker, +) -> None: + """Ensure missing arg raises an error.""" + func_node = astroid.extract_node( + """ + async def async_setup_entry( #@ + hass: HomeAssistant, + entry: ConfigEntry, + ) -> None: + pass + """, + "homeassistant.components.pylint_test.sensor", + ) + type_hint_checker.visit_module(func_node.parent) + + with assert_adds_messages( + linter, + pylint.testutils.MessageTest( + msg_id="hass-argument-type", + node=func_node, + args=( + 3, + "AddConfigEntryEntitiesCallback", + "async_setup_entry", + ), + line=2, + col_offset=0, + end_line=2, + end_col_offset=27, + ), + ): + type_hint_checker.visit_asyncfunctiondef(func_node)