mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Disable pylint ignore_missing_annotations in config flow (#125322)
* Disable pylint ignore_missing_annotations in config flow * Add tests * Ignore point
This commit is contained in:
parent
15bf6222f5
commit
18e2c2f6dd
@ -25,6 +25,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
# pylint: disable-next=hass-argument-type # see PR 118243
|
||||||
def register_flow_implementation(hass, domain, client_id, client_secret):
|
def register_flow_implementation(hass, domain, client_id, client_secret):
|
||||||
"""Register a flow implementation.
|
"""Register a flow implementation.
|
||||||
|
|
||||||
@ -51,6 +52,7 @@ class PointFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
"""Initialize flow."""
|
"""Initialize flow."""
|
||||||
self.flow_impl = None
|
self.flow_impl = None
|
||||||
|
|
||||||
|
# pylint: disable-next=hass-return-type # see PR 118243
|
||||||
async def async_step_import(self, user_input=None):
|
async def async_step_import(self, user_input=None):
|
||||||
"""Handle external yaml configuration."""
|
"""Handle external yaml configuration."""
|
||||||
if self._async_current_entries():
|
if self._async_current_entries():
|
||||||
@ -86,6 +88,7 @@ class PointFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
data_schema=vol.Schema({vol.Required("flow_impl"): vol.In(list(flows))}),
|
data_schema=vol.Schema({vol.Required("flow_impl"): vol.In(list(flows))}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# pylint: disable-next=hass-return-type # see PR 118243
|
||||||
async def async_step_auth(self, user_input=None):
|
async def async_step_auth(self, user_input=None):
|
||||||
"""Create an entry for auth."""
|
"""Create an entry for auth."""
|
||||||
if self._async_current_entries():
|
if self._async_current_entries():
|
||||||
@ -125,6 +128,7 @@ class PointFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
return point_session.get_authorization_url
|
return point_session.get_authorization_url
|
||||||
|
|
||||||
|
# pylint: disable-next=hass-return-type # see PR 118243
|
||||||
async def async_step_code(self, code=None):
|
async def async_step_code(self, code=None):
|
||||||
"""Received code for authentication."""
|
"""Received code for authentication."""
|
||||||
if self._async_current_entries():
|
if self._async_current_entries():
|
||||||
|
@ -28,6 +28,8 @@ _KNOWN_GENERIC_TYPES: set[str] = {
|
|||||||
}
|
}
|
||||||
_KNOWN_GENERIC_TYPES_TUPLE = tuple(_KNOWN_GENERIC_TYPES)
|
_KNOWN_GENERIC_TYPES_TUPLE = tuple(_KNOWN_GENERIC_TYPES)
|
||||||
|
|
||||||
|
_FORCE_ANNOTATION_PLATFORMS = ["config_flow"]
|
||||||
|
|
||||||
|
|
||||||
class _Special(Enum):
|
class _Special(Enum):
|
||||||
"""Sentinel values."""
|
"""Sentinel values."""
|
||||||
@ -3108,6 +3110,7 @@ class HassTypeHintChecker(BaseChecker):
|
|||||||
_class_matchers: list[ClassTypeHintMatch]
|
_class_matchers: list[ClassTypeHintMatch]
|
||||||
_function_matchers: list[TypeHintMatch]
|
_function_matchers: list[TypeHintMatch]
|
||||||
_module_node: nodes.Module
|
_module_node: nodes.Module
|
||||||
|
_module_platform: str | None
|
||||||
_in_test_module: bool
|
_in_test_module: bool
|
||||||
|
|
||||||
def visit_module(self, node: nodes.Module) -> None:
|
def visit_module(self, node: nodes.Module) -> None:
|
||||||
@ -3115,24 +3118,22 @@ class HassTypeHintChecker(BaseChecker):
|
|||||||
self._class_matchers = []
|
self._class_matchers = []
|
||||||
self._function_matchers = []
|
self._function_matchers = []
|
||||||
self._module_node = node
|
self._module_node = node
|
||||||
|
self._module_platform = _get_module_platform(node.name)
|
||||||
self._in_test_module = node.name.startswith("tests.")
|
self._in_test_module = node.name.startswith("tests.")
|
||||||
|
|
||||||
if (
|
if self._in_test_module or self._module_platform is None:
|
||||||
self._in_test_module
|
|
||||||
or (module_platform := _get_module_platform(node.name)) is None
|
|
||||||
):
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if module_platform in _PLATFORMS:
|
if self._module_platform in _PLATFORMS:
|
||||||
self._function_matchers.extend(_FUNCTION_MATCH["__any_platform__"])
|
self._function_matchers.extend(_FUNCTION_MATCH["__any_platform__"])
|
||||||
|
|
||||||
if function_matches := _FUNCTION_MATCH.get(module_platform):
|
if function_matches := _FUNCTION_MATCH.get(self._module_platform):
|
||||||
self._function_matchers.extend(function_matches)
|
self._function_matchers.extend(function_matches)
|
||||||
|
|
||||||
if class_matches := _CLASS_MATCH.get(module_platform):
|
if class_matches := _CLASS_MATCH.get(self._module_platform):
|
||||||
self._class_matchers.extend(class_matches)
|
self._class_matchers.extend(class_matches)
|
||||||
|
|
||||||
if property_matches := _INHERITANCE_MATCH.get(module_platform):
|
if property_matches := _INHERITANCE_MATCH.get(self._module_platform):
|
||||||
self._class_matchers.extend(property_matches)
|
self._class_matchers.extend(property_matches)
|
||||||
|
|
||||||
self._class_matchers.reverse()
|
self._class_matchers.reverse()
|
||||||
@ -3142,7 +3143,12 @@ class HassTypeHintChecker(BaseChecker):
|
|||||||
) -> bool:
|
) -> bool:
|
||||||
"""Check if we can skip the function validation."""
|
"""Check if we can skip the function validation."""
|
||||||
return (
|
return (
|
||||||
self.linter.config.ignore_missing_annotations
|
# test modules are excluded from ignore_missing_annotations
|
||||||
|
not self._in_test_module
|
||||||
|
# some modules have checks forced
|
||||||
|
and self._module_platform not in _FORCE_ANNOTATION_PLATFORMS
|
||||||
|
# other modules are only checked ignore_missing_annotations
|
||||||
|
and self.linter.config.ignore_missing_annotations
|
||||||
and node.returns is None
|
and node.returns is None
|
||||||
and not _has_valid_annotations(annotations)
|
and not _has_valid_annotations(annotations)
|
||||||
)
|
)
|
||||||
|
@ -313,7 +313,9 @@ def test_invalid_config_flow_step(
|
|||||||
linter: UnittestLinter, type_hint_checker: BaseChecker
|
linter: UnittestLinter, type_hint_checker: BaseChecker
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Ensure invalid hints are rejected for ConfigFlow step."""
|
"""Ensure invalid hints are rejected for ConfigFlow step."""
|
||||||
class_node, func_node, arg_node = astroid.extract_node(
|
type_hint_checker.linter.config.ignore_missing_annotations = True
|
||||||
|
|
||||||
|
class_node, func_node, arg_node, func_node2 = astroid.extract_node(
|
||||||
"""
|
"""
|
||||||
class FlowHandler():
|
class FlowHandler():
|
||||||
pass
|
pass
|
||||||
@ -329,6 +331,12 @@ def test_invalid_config_flow_step(
|
|||||||
device_config: dict #@
|
device_config: dict #@
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
async def async_step_custom( #@
|
||||||
|
self,
|
||||||
|
user_input
|
||||||
|
):
|
||||||
|
pass
|
||||||
""",
|
""",
|
||||||
"homeassistant.components.pylint_test.config_flow",
|
"homeassistant.components.pylint_test.config_flow",
|
||||||
)
|
)
|
||||||
@ -354,6 +362,15 @@ def test_invalid_config_flow_step(
|
|||||||
end_line=11,
|
end_line=11,
|
||||||
end_col_offset=33,
|
end_col_offset=33,
|
||||||
),
|
),
|
||||||
|
pylint.testutils.MessageTest(
|
||||||
|
msg_id="hass-return-type",
|
||||||
|
node=func_node2,
|
||||||
|
args=("ConfigFlowResult", "async_step_custom"),
|
||||||
|
line=17,
|
||||||
|
col_offset=4,
|
||||||
|
end_line=17,
|
||||||
|
end_col_offset=31,
|
||||||
|
),
|
||||||
):
|
):
|
||||||
type_hint_checker.visit_classdef(class_node)
|
type_hint_checker.visit_classdef(class_node)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user