diff --git a/homeassistant/components/point/config_flow.py b/homeassistant/components/point/config_flow.py index b2455438208163..390a2691c806bf 100644 --- a/homeassistant/components/point/config_flow.py +++ b/homeassistant/components/point/config_flow.py @@ -25,6 +25,7 @@ @callback +# pylint: disable-next=hass-argument-type # see PR 118243 def register_flow_implementation(hass, domain, client_id, client_secret): """Register a flow implementation. @@ -51,6 +52,7 @@ def __init__(self) -> None: """Initialize flow.""" self.flow_impl = None + # pylint: disable-next=hass-return-type # see PR 118243 async def async_step_import(self, user_input=None): """Handle external yaml configuration.""" if self._async_current_entries(): @@ -86,6 +88,7 @@ async def async_step_user( 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): """Create an entry for auth.""" if self._async_current_entries(): @@ -125,6 +128,7 @@ async def _get_authorization_url(self): return point_session.get_authorization_url + # pylint: disable-next=hass-return-type # see PR 118243 async def async_step_code(self, code=None): """Received code for authentication.""" if self._async_current_entries(): diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index 13499134668940..7f4a7fbd485d43 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -28,6 +28,8 @@ } _KNOWN_GENERIC_TYPES_TUPLE = tuple(_KNOWN_GENERIC_TYPES) +_FORCE_ANNOTATION_PLATFORMS = ["config_flow"] + class _Special(Enum): """Sentinel values.""" @@ -3108,6 +3110,7 @@ class HassTypeHintChecker(BaseChecker): _class_matchers: list[ClassTypeHintMatch] _function_matchers: list[TypeHintMatch] _module_node: nodes.Module + _module_platform: str | None _in_test_module: bool def visit_module(self, node: nodes.Module) -> None: @@ -3115,24 +3118,22 @@ def visit_module(self, node: nodes.Module) -> None: self._class_matchers = [] self._function_matchers = [] self._module_node = node + self._module_platform = _get_module_platform(node.name) self._in_test_module = node.name.startswith("tests.") - if ( - self._in_test_module - or (module_platform := _get_module_platform(node.name)) is None - ): + if self._in_test_module or self._module_platform is None: return - if module_platform in _PLATFORMS: + if self._module_platform in _PLATFORMS: 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) - if class_matches := _CLASS_MATCH.get(module_platform): + if class_matches := _CLASS_MATCH.get(self._module_platform): 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.reverse() @@ -3142,7 +3143,12 @@ def _ignore_function( ) -> bool: """Check if we can skip the function validation.""" 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 not _has_valid_annotations(annotations) ) diff --git a/tests/pylint/test_enforce_type_hints.py b/tests/pylint/test_enforce_type_hints.py index b1692d1d60dc9e..6c53e9832d935c 100644 --- a/tests/pylint/test_enforce_type_hints.py +++ b/tests/pylint/test_enforce_type_hints.py @@ -313,7 +313,9 @@ def test_invalid_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( + type_hint_checker.linter.config.ignore_missing_annotations = True + + class_node, func_node, arg_node, func_node2 = astroid.extract_node( """ class FlowHandler(): pass @@ -329,6 +331,12 @@ async def async_step_zeroconf( #@ device_config: dict #@ ): pass + + async def async_step_custom( #@ + self, + user_input + ): + pass """, "homeassistant.components.pylint_test.config_flow", ) @@ -354,6 +362,15 @@ async def async_step_zeroconf( #@ end_line=11, 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)