diff --git a/pylint/plugins/hass_constructor.py b/pylint/plugins/hass_constructor.py deleted file mode 100644 index b2db7ba429b..00000000000 --- a/pylint/plugins/hass_constructor.py +++ /dev/null @@ -1,51 +0,0 @@ -"""Plugin for constructor definitions.""" -from __future__ import annotations - -from astroid import nodes -from pylint.checkers import BaseChecker -from pylint.lint import PyLinter - - -class HassConstructorFormatChecker(BaseChecker): # type: ignore[misc] - """Checker for __init__ definitions.""" - - name = "hass_constructor" - priority = -1 - msgs = { - "W7411": ( - '__init__ should have explicit return type "None"', - "hass-constructor-return", - "Used when __init__ has all arguments typed " - "but doesn't have return type declared", - ), - } - options = () - - def visit_functiondef(self, node: nodes.FunctionDef) -> None: - """Check for improperly typed `__init__` definitions.""" - if not node.is_method() or node.name != "__init__": - return - - # Check that all arguments are annotated. - # The first argument is "self". - args = node.args - annotations = ( - args.posonlyargs_annotations - + args.annotations - + args.kwonlyargs_annotations - )[1:] - if args.vararg is not None: - annotations.append(args.varargannotation) - if args.kwarg is not None: - annotations.append(args.kwargannotation) - if not annotations or None in annotations: - return - - # Check that return type is specified and it is "None". - if not isinstance(node.returns, nodes.Const) or node.returns.value is not None: - self.add_message("hass-constructor-return", node=node) - - -def register(linter: PyLinter) -> None: - """Register the checker.""" - linter.register_checker(HassConstructorFormatChecker(linter)) diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index 15f5890c0f7..e5659be06cb 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -83,6 +83,13 @@ _TYPE_HINT_MATCHERS.update( _MODULE_REGEX: re.Pattern[str] = re.compile(r"^homeassistant\.components\.\w+(\.\w+)?$") +_METHOD_MATCH: list[TypeHintMatch] = [ + TypeHintMatch( + function_name="__init__", + return_type=None, + ), +] + _FUNCTION_MATCH: dict[str, list[TypeHintMatch]] = { "__init__": [ TypeHintMatch( @@ -2973,9 +2980,13 @@ class HassTypeHintChecker(BaseChecker): # type: ignore[misc] args=(arg_name, expected_type, node.name), ) - # Check function matchers. - for match in self._function_matchers: - if not match.need_to_check_function(node) or node.is_method(): + # Check method or function matchers. + if node.is_method(): + matchers = _METHOD_MATCH + else: + matchers = self._function_matchers + for match in matchers: + if not match.need_to_check_function(node): continue self._check_function(node, match, annotations) diff --git a/pyproject.toml b/pyproject.toml index affe111ef28..10fcb128af6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -112,7 +112,6 @@ init-hook = """\ load-plugins = [ "pylint.extensions.code_style", "pylint.extensions.typing", - "hass_constructor", "hass_enforce_type_hints", "hass_imports", "hass_logger",