1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-22 11:59:34 +00:00

Prevent NumberEntity and RestoreEntity inheritance (#93467)

This commit is contained in:
epenet
2023-05-24 20:59:14 +02:00
committed by GitHub
parent dc3826f68e
commit 6057aeee2f
3 changed files with 47 additions and 1 deletions

View File

@@ -45,7 +45,7 @@ class HassInheritanceChecker(BaseChecker): # type: ignore[misc]
def visit_classdef(self, node: nodes.ClassDef) -> None:
"""Apply relevant type hint checks on a ClassDef node."""
if self._module_platform != "sensor":
if self._module_platform not in {"number", "sensor"}:
return
ancestors = [a.name for a in node.ancestors()]
@@ -59,6 +59,16 @@ class HassInheritanceChecker(BaseChecker): # type: ignore[misc]
node=node,
args="SensorEntity and RestoreEntity should not be combined, please use RestoreSensor",
)
elif (
"RestoreEntity" in ancestors
and "NumberEntity" in ancestors
and "RestoreNumber" not in ancestors
):
self.add_message(
"hass-invalid-inheritance",
node=node,
args="NumberEntity and RestoreEntity should not be combined, please use RestoreNumber",
)
def register(linter: PyLinter) -> None: