mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Adjust pylint plugin for relative imports (#78277)
This commit is contained in:
parent
d3be06906b
commit
f1c7fb7866
@ -362,14 +362,18 @@ class HassImportsFormatChecker(BaseChecker): # type: ignore[misc]
|
|||||||
):
|
):
|
||||||
self.add_message("hass-relative-import", node=node)
|
self.add_message("hass-relative-import", node=node)
|
||||||
return
|
return
|
||||||
if (
|
if self.current_package.startswith("homeassistant.components."):
|
||||||
self.current_package.startswith("homeassistant.components")
|
current_component = self.current_package.split(".")[2]
|
||||||
and node.modname == "homeassistant.components"
|
if node.modname == "homeassistant.components":
|
||||||
):
|
for name in node.names:
|
||||||
for name in node.names:
|
if name[0] == current_component:
|
||||||
if name[0] == self.current_package.split(".")[2]:
|
self.add_message("hass-relative-import", node=node)
|
||||||
self.add_message("hass-relative-import", node=node)
|
return
|
||||||
return
|
if node.modname.startswith(
|
||||||
|
f"homeassistant.components.{current_component}."
|
||||||
|
):
|
||||||
|
self.add_message("hass-relative-import", node=node)
|
||||||
|
return
|
||||||
if obsolete_imports := _OBSOLETE_IMPORT.get(node.modname):
|
if obsolete_imports := _OBSOLETE_IMPORT.get(node.modname):
|
||||||
for name_tuple in node.names:
|
for name_tuple in node.names:
|
||||||
for obsolete_import in obsolete_imports:
|
for obsolete_import in obsolete_imports:
|
||||||
|
@ -19,6 +19,11 @@ from . import assert_adds_messages, assert_no_messages
|
|||||||
"homeassistant.const",
|
"homeassistant.const",
|
||||||
"CONSTANT",
|
"CONSTANT",
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"homeassistant.components.pylint_test.sensor",
|
||||||
|
"homeassistant.components.pylint_testing",
|
||||||
|
"CONSTANT",
|
||||||
|
),
|
||||||
("homeassistant.components.pylint_test.sensor", ".const", "CONSTANT"),
|
("homeassistant.components.pylint_test.sensor", ".const", "CONSTANT"),
|
||||||
("homeassistant.components.pylint_test.sensor", ".", "CONSTANT"),
|
("homeassistant.components.pylint_test.sensor", ".", "CONSTANT"),
|
||||||
("homeassistant.components.pylint_test.sensor", "..", "pylint_test"),
|
("homeassistant.components.pylint_test.sensor", "..", "pylint_test"),
|
||||||
@ -90,6 +95,12 @@ def test_good_import(
|
|||||||
"pylint_test",
|
"pylint_test",
|
||||||
"hass-relative-import",
|
"hass-relative-import",
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"homeassistant.components.pylint_test.api.hub",
|
||||||
|
"homeassistant.components.pylint_test.const",
|
||||||
|
"CONSTANT",
|
||||||
|
"hass-relative-import",
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_bad_import(
|
def test_bad_import(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user