Adjust pylint plugin for relative imports (#78277)

This commit is contained in:
epenet
2022-09-14 00:11:57 +02:00
committed by GitHub
parent d3be06906b
commit f1c7fb7866
2 changed files with 23 additions and 8 deletions

View File

@@ -362,14 +362,18 @@ class HassImportsFormatChecker(BaseChecker): # type: ignore[misc]
):
self.add_message("hass-relative-import", node=node)
return
if (
self.current_package.startswith("homeassistant.components")
and node.modname == "homeassistant.components"
):
for name in node.names:
if name[0] == self.current_package.split(".")[2]:
self.add_message("hass-relative-import", node=node)
return
if self.current_package.startswith("homeassistant.components."):
current_component = self.current_package.split(".")[2]
if node.modname == "homeassistant.components":
for name in node.names:
if name[0] == current_component:
self.add_message("hass-relative-import", node=node)
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):
for name_tuple in node.names:
for obsolete_import in obsolete_imports: