From 2f95d1ef7858e607addf0197775f736583dcebab Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 23 Feb 2026 16:50:52 +0100 Subject: [PATCH] Mark lock entity type hints as mandatory (#163796) --- pylint/plugins/hass_enforce_type_hints.py | 10 +++++++ tests/pylint/test_enforce_type_hints.py | 32 +++++++++++++++++++---- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index 744ec1fed90..1cd47c78899 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -1964,48 +1964,58 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = { TypeHintMatch( function_name="changed_by", return_type=["str", None], + mandatory=True, ), TypeHintMatch( function_name="code_format", return_type=["str", None], + mandatory=True, ), TypeHintMatch( function_name="is_locked", return_type=["bool", None], + mandatory=True, ), TypeHintMatch( function_name="is_locking", return_type=["bool", None], + mandatory=True, ), TypeHintMatch( function_name="is_unlocking", return_type=["bool", None], + mandatory=True, ), TypeHintMatch( function_name="is_jammed", return_type=["bool", None], + mandatory=True, ), TypeHintMatch( function_name="supported_features", return_type="LockEntityFeature", + mandatory=True, ), TypeHintMatch( function_name="lock", kwargs_type="Any", return_type=None, has_async_counterpart=True, + mandatory=True, ), TypeHintMatch( function_name="unlock", kwargs_type="Any", return_type=None, has_async_counterpart=True, + mandatory=True, ), TypeHintMatch( function_name="open", kwargs_type="Any", return_type=None, has_async_counterpart=True, + mandatory=True, ), ], ), diff --git a/tests/pylint/test_enforce_type_hints.py b/tests/pylint/test_enforce_type_hints.py index fac9cf0785c..d65b69a7b8b 100644 --- a/tests/pylint/test_enforce_type_hints.py +++ b/tests/pylint/test_enforce_type_hints.py @@ -679,9 +679,15 @@ def test_invalid_entity_properties( def test_ignore_invalid_entity_properties( - linter: UnittestLinter, type_hint_checker: BaseChecker + hass_enforce_type_hints: ModuleType, + linter: UnittestLinter, + type_hint_checker: BaseChecker, ) -> None: - """Check invalid entity properties are ignored by default.""" + """Check invalid entity properties are ignored by default. + + - ignore missing annotations is set to True + - mandatory is set to False for lock and changed_by functions + """ # Set ignore option type_hint_checker.linter.config.ignore_missing_annotations = True @@ -710,10 +716,26 @@ def test_ignore_invalid_entity_properties( """, "homeassistant.components.pylint_test.lock", ) - type_hint_checker.visit_module(class_node.parent) + lock_match = next( + function_match + for class_match in hass_enforce_type_hints._INHERITANCE_MATCH["lock"] + for function_match in class_match.matches + if function_match.function_name == "lock" + ) + changed_by_match = next( + function_match + for class_match in hass_enforce_type_hints._INHERITANCE_MATCH["lock"] + for function_match in class_match.matches + if function_match.function_name == "changed_by" + ) + with ( + patch.object(lock_match, "mandatory", False), + patch.object(changed_by_match, "mandatory", False), + ): + type_hint_checker.visit_module(class_node.parent) - with assert_no_messages(linter): - type_hint_checker.visit_classdef(class_node) + with assert_no_messages(linter): + type_hint_checker.visit_classdef(class_node) def test_named_arguments(