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:
epenet 2024-09-16 11:53:29 +02:00 committed by GitHub
parent 15bf6222f5
commit 18e2c2f6dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 10 deletions

View File

@ -25,6 +25,7 @@ _LOGGER = logging.getLogger(__name__)
@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 @@ class PointFlowHandler(ConfigFlow, domain=DOMAIN):
"""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 @@ class PointFlowHandler(ConfigFlow, domain=DOMAIN):
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 @@ class PointFlowHandler(ConfigFlow, domain=DOMAIN):
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():

View File

@ -28,6 +28,8 @@ _KNOWN_GENERIC_TYPES: set[str] = {
}
_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 @@ class HassTypeHintChecker(BaseChecker):
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 @@ class HassTypeHintChecker(BaseChecker):
) -> 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)
)

View File

@ -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 @@ def test_invalid_config_flow_step(
device_config: dict #@
):
pass
async def async_step_custom( #@
self,
user_input
):
pass
""",
"homeassistant.components.pylint_test.config_flow",
)
@ -354,6 +362,15 @@ def test_invalid_config_flow_step(
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)