1
0
mirror of https://github.com/home-assistant/core.git synced 2026-02-25 20:35:09 +00:00

Mark lock entity type hints as mandatory (#163796)

This commit is contained in:
epenet
2026-02-23 16:50:52 +01:00
committed by GitHub
parent 6d6727ed58
commit 2f95d1ef78
2 changed files with 37 additions and 5 deletions

View File

@@ -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,
),
],
),

View File

@@ -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(