mirror of
https://github.com/home-assistant/core.git
synced 2026-02-15 07:36:16 +00:00
Handle missing argument in hass_enforce_type_hints (#152342)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user