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

Adjust astroid import in pylint plugin (#72841)

* import nodes from astroid

* Update remaining pylint plugins

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
This commit is contained in:
epenet
2022-06-02 07:48:59 +02:00
committed by GitHub
parent f79e5e002b
commit 999b3a4f7b
4 changed files with 39 additions and 35 deletions

View File

@@ -4,7 +4,7 @@ from __future__ import annotations
from dataclasses import dataclass
import re
from astroid import Import, ImportFrom, Module
from astroid import nodes
from pylint.checkers import BaseChecker
from pylint.interfaces import IAstroidChecker
from pylint.lint import PyLinter
@@ -14,7 +14,7 @@ from pylint.lint import PyLinter
class ObsoleteImportMatch:
"""Class for pattern matching."""
constant: re.Pattern
constant: re.Pattern[str]
reason: str
@@ -255,7 +255,7 @@ class HassImportsFormatChecker(BaseChecker): # type: ignore[misc]
super().__init__(linter)
self.current_package: str | None = None
def visit_module(self, node: Module) -> None:
def visit_module(self, node: nodes.Module) -> None:
"""Called when a Module node is visited."""
if node.package:
self.current_package = node.name
@@ -263,13 +263,13 @@ class HassImportsFormatChecker(BaseChecker): # type: ignore[misc]
# Strip name of the current module
self.current_package = node.name[: node.name.rfind(".")]
def visit_import(self, node: Import) -> None:
def visit_import(self, node: nodes.Import) -> None:
"""Called when a Import node is visited."""
for module, _alias in node.names:
if module.startswith(f"{self.current_package}."):
self.add_message("hass-relative-import", node=node)
def visit_importfrom(self, node: ImportFrom) -> None:
def visit_importfrom(self, node: nodes.ImportFrom) -> None:
"""Called when a ImportFrom node is visited."""
if node.level is not None:
return