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

Disable pylint ignore_missing_annotations in config flow #125322

Merged
merged 3 commits into from
Sep 16, 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
4 changes: 4 additions & 0 deletions homeassistant/components/point/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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():
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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():
Expand Down
24 changes: 15 additions & 9 deletions pylint/plugins/hass_enforce_type_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
}
_KNOWN_GENERIC_TYPES_TUPLE = tuple(_KNOWN_GENERIC_TYPES)

_FORCE_ANNOTATION_PLATFORMS = ["config_flow"]


class _Special(Enum):
"""Sentinel values."""
Expand Down Expand Up @@ -3108,31 +3110,30 @@ 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:
"""Populate matchers for a Module node."""
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()
Expand All @@ -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)
)
Expand Down
19 changes: 18 additions & 1 deletion tests/pylint/test_enforce_type_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
)
Expand All @@ -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)

Expand Down
Loading