Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove config flow specifics from FlowResult #111932

Merged
merged 3 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion homeassistant/config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,11 @@ class OperationNotAllowed(ConfigError):
}


ConfigFlowResult = FlowResult
class ConfigFlowResult(FlowResult, total=False):
"""Typed result dict for config flow."""

minor_version: int
version: int


class ConfigEntry:
Expand Down
2 changes: 0 additions & 2 deletions homeassistant/data_entry_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ class FlowResult(TypedDict, total=False):
handler: Required[str]
last_step: bool | None
menu_options: list[str] | dict[str, str]
minor_version: int
options: Mapping[str, Any]
preview: str | None
progress_action: str
Expand All @@ -164,7 +163,6 @@ class FlowResult(TypedDict, total=False):
translation_domain: str
type: FlowResultType
url: str
version: int


def _map_error_to_schema_errors(
Expand Down
28 changes: 14 additions & 14 deletions pylint/plugins/hass_enforce_type_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,6 @@ class ClassTypeHintMatch:
ClassTypeHintMatch(
base_class="ConfigFlow",
matches=[
TypeHintMatch(
function_name="async_step123_*",
arg_types={},
return_type=["ConfigFlowResult", "FlowResult"],
),
TypeHintMatch(
function_name="async_get_options_flow",
arg_types={
Expand All @@ -511,56 +506,61 @@ class ClassTypeHintMatch:
arg_types={
1: "DhcpServiceInfo",
},
return_type=["ConfigFlowResult", "FlowResult"],
return_type="ConfigFlowResult",
),
TypeHintMatch(
function_name="async_step_hassio",
arg_types={
1: "HassioServiceInfo",
},
return_type=["ConfigFlowResult", "FlowResult"],
return_type="ConfigFlowResult",
),
TypeHintMatch(
function_name="async_step_homekit",
arg_types={
1: "ZeroconfServiceInfo",
},
return_type=["ConfigFlowResult", "FlowResult"],
return_type="ConfigFlowResult",
),
TypeHintMatch(
function_name="async_step_mqtt",
arg_types={
1: "MqttServiceInfo",
},
return_type=["ConfigFlowResult", "FlowResult"],
return_type="ConfigFlowResult",
),
TypeHintMatch(
function_name="async_step_reauth",
arg_types={
1: "Mapping[str, Any]",
},
return_type=["ConfigFlowResult", "FlowResult"],
return_type="ConfigFlowResult",
),
TypeHintMatch(
function_name="async_step_ssdp",
arg_types={
1: "SsdpServiceInfo",
},
return_type=["ConfigFlowResult", "FlowResult"],
return_type="ConfigFlowResult",
),
TypeHintMatch(
function_name="async_step_usb",
arg_types={
1: "UsbServiceInfo",
},
return_type=["ConfigFlowResult", "FlowResult"],
return_type="ConfigFlowResult",
),
TypeHintMatch(
function_name="async_step_zeroconf",
arg_types={
1: "ZeroconfServiceInfo",
},
return_type=["ConfigFlowResult", "FlowResult"],
return_type="ConfigFlowResult",
),
TypeHintMatch(
function_name="async_step_*",
arg_types={},
return_type="ConfigFlowResult",
),
],
),
Expand All @@ -570,7 +570,7 @@ class ClassTypeHintMatch:
TypeHintMatch(
function_name="async_step_*",
arg_types={},
return_type=["ConfigFlowResult", "FlowResult"],
return_type="ConfigFlowResult",
),
],
),
Expand Down
42 changes: 41 additions & 1 deletion tests/pylint/test_enforce_type_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ async def async_step_zeroconf( #@
pylint.testutils.MessageTest(
msg_id="hass-return-type",
node=func_node,
args=(["ConfigFlowResult", "FlowResult"], "async_step_zeroconf"),
args=("ConfigFlowResult", "async_step_zeroconf"),
line=11,
col_offset=4,
end_line=11,
Expand All @@ -356,6 +356,46 @@ async def async_step_zeroconf( #@
type_hint_checker.visit_classdef(class_node)


def test_invalid_custom_config_flow_step(
linter: UnittestLinter, type_hint_checker: BaseChecker
) -> None:
"""Ensure invalid hints are rejected for ConfigFlow step."""
class_node, func_node, arg_node = astroid.extract_node(
"""
class FlowHandler():
pass

class ConfigFlow(FlowHandler):
pass

class AxisFlowHandler( #@
ConfigFlow, domain=AXIS_DOMAIN
):
async def async_step_axis_specific( #@
self,
device_config: dict #@
):
pass
""",
"homeassistant.components.pylint_test.config_flow",
)
type_hint_checker.visit_module(class_node.parent)

with assert_adds_messages(
linter,
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,
),
):
type_hint_checker.visit_classdef(class_node)


def test_valid_config_flow_step(
linter: UnittestLinter, type_hint_checker: BaseChecker
) -> None:
Expand Down
Loading