mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Fix hassfest type hints for ConfigSubentryFlow (#143502)
This commit is contained in:
parent
8215faea0d
commit
3cb301214f
@ -597,6 +597,16 @@ _CLASS_MATCH: dict[str, list[ClassTypeHintMatch]] = {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
ClassTypeHintMatch(
|
||||||
|
base_class="ConfigSubentryFlow",
|
||||||
|
matches=[
|
||||||
|
TypeHintMatch(
|
||||||
|
function_name="async_step_*",
|
||||||
|
arg_types={},
|
||||||
|
return_type="SubentryFlowResult",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
# Overriding properties and functions are normally checked by mypy, and will only
|
# Overriding properties and functions are normally checked by mypy, and will only
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
import re
|
import re
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
@ -375,12 +376,11 @@ def test_invalid_config_flow_step(
|
|||||||
type_hint_checker.visit_classdef(class_node)
|
type_hint_checker.visit_classdef(class_node)
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_custom_config_flow_step(
|
@pytest.mark.parametrize(
|
||||||
linter: UnittestLinter, type_hint_checker: BaseChecker
|
("code", "expected_messages_fn"),
|
||||||
) -> None:
|
[
|
||||||
"""Ensure invalid hints are rejected for ConfigFlow step."""
|
(
|
||||||
class_node, func_node, arg_node = astroid.extract_node(
|
"""
|
||||||
"""
|
|
||||||
class FlowHandler():
|
class FlowHandler():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -392,34 +392,79 @@ def test_invalid_custom_config_flow_step(
|
|||||||
):
|
):
|
||||||
async def async_step_axis_specific( #@
|
async def async_step_axis_specific( #@
|
||||||
self,
|
self,
|
||||||
device_config: dict #@
|
device_config: dict
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
""",
|
""",
|
||||||
|
lambda func_node: [
|
||||||
|
pylint.testutils.MessageTest(
|
||||||
|
msg_id="hass-return-type",
|
||||||
|
node=func_node,
|
||||||
|
args=("ConfigFlowResult", "async_step_axis_specific"),
|
||||||
|
line=11,
|
||||||
|
col_offset=4,
|
||||||
|
end_line=11,
|
||||||
|
end_col_offset=38,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"""
|
||||||
|
class FlowHandler():
|
||||||
|
pass
|
||||||
|
|
||||||
|
class ConfigSubentryFlow(FlowHandler):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class CustomSubentryFlowHandler(ConfigSubentryFlow): #@
|
||||||
|
async def async_step_user( #@
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
|
pass
|
||||||
|
""",
|
||||||
|
lambda func_node: [
|
||||||
|
pylint.testutils.MessageTest(
|
||||||
|
msg_id="hass-return-type",
|
||||||
|
node=func_node,
|
||||||
|
args=("SubentryFlowResult", "async_step_user"),
|
||||||
|
line=9,
|
||||||
|
col_offset=4,
|
||||||
|
end_line=9,
|
||||||
|
end_col_offset=29,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
ids=[
|
||||||
|
"Config flow",
|
||||||
|
"Config subentry flow",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_invalid_flow_step(
|
||||||
|
linter: UnittestLinter,
|
||||||
|
type_hint_checker: BaseChecker,
|
||||||
|
code: str,
|
||||||
|
expected_messages_fn: Callable[
|
||||||
|
[astroid.NodeNG], tuple[pylint.testutils.MessageTest, ...]
|
||||||
|
],
|
||||||
|
) -> None:
|
||||||
|
"""Ensure invalid hints are rejected for flow step."""
|
||||||
|
class_node, func_node = astroid.extract_node(
|
||||||
|
code,
|
||||||
"homeassistant.components.pylint_test.config_flow",
|
"homeassistant.components.pylint_test.config_flow",
|
||||||
)
|
)
|
||||||
type_hint_checker.visit_module(class_node.parent)
|
type_hint_checker.visit_module(class_node.parent)
|
||||||
|
|
||||||
with assert_adds_messages(
|
with assert_adds_messages(
|
||||||
linter,
|
linter,
|
||||||
pylint.testutils.MessageTest(
|
*expected_messages_fn(func_node),
|
||||||
msg_id="hass-return-type",
|
|
||||||
node=func_node,
|
|
||||||
args=("ConfigFlowResult", "async_step_axis_specific"),
|
|
||||||
line=11,
|
|
||||||
col_offset=4,
|
|
||||||
end_line=11,
|
|
||||||
end_col_offset=38,
|
|
||||||
),
|
|
||||||
):
|
):
|
||||||
type_hint_checker.visit_classdef(class_node)
|
type_hint_checker.visit_classdef(class_node)
|
||||||
|
|
||||||
|
|
||||||
def test_valid_config_flow_step(
|
@pytest.mark.parametrize(
|
||||||
linter: UnittestLinter, type_hint_checker: BaseChecker
|
"code",
|
||||||
) -> None:
|
[
|
||||||
"""Ensure valid hints are accepted for ConfigFlow step."""
|
|
||||||
class_node = astroid.extract_node(
|
|
||||||
"""
|
"""
|
||||||
class FlowHandler():
|
class FlowHandler():
|
||||||
pass
|
pass
|
||||||
@ -436,6 +481,33 @@ def test_valid_config_flow_step(
|
|||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
pass
|
pass
|
||||||
""",
|
""",
|
||||||
|
"""
|
||||||
|
class FlowHandler():
|
||||||
|
pass
|
||||||
|
|
||||||
|
class ConfigSubentryFlow(FlowHandler):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class CustomSubentryFlowHandler(ConfigSubentryFlow): #@
|
||||||
|
async def async_step_user(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> SubentryFlowResult:
|
||||||
|
pass
|
||||||
|
""",
|
||||||
|
],
|
||||||
|
ids=[
|
||||||
|
"Config flow",
|
||||||
|
"Config subentry flow",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_valid_flow_step(
|
||||||
|
linter: UnittestLinter,
|
||||||
|
type_hint_checker: BaseChecker,
|
||||||
|
code: str,
|
||||||
|
) -> None:
|
||||||
|
"""Ensure valid hints are accepted for flow step."""
|
||||||
|
class_node = astroid.extract_node(
|
||||||
|
code,
|
||||||
"homeassistant.components.pylint_test.config_flow",
|
"homeassistant.components.pylint_test.config_flow",
|
||||||
)
|
)
|
||||||
type_hint_checker.visit_module(class_node.parent)
|
type_hint_checker.visit_module(class_node.parent)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user