diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cb9a5ed04dc..56faefc1a85 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ repos: args: - --safe - --quiet - files: ^((homeassistant|script|tests)/.+)?[^/]+\.py$ + files: ^((homeassistant|pylint|script|tests)/.+)?[^/]+\.py$ - repo: https://github.com/codespell-project/codespell rev: v2.1.0 hooks: diff --git a/pylint/plugins/hass_imports.py b/pylint/plugins/hass_imports.py index 6068e1c2baf..a45e2c91996 100644 --- a/pylint/plugins/hass_imports.py +++ b/pylint/plugins/hass_imports.py @@ -303,9 +303,13 @@ class HassImportsFormatChecker(BaseChecker): # type: ignore[misc] if module.startswith(f"{self.current_package}."): self.add_message("hass-relative-import", node=node) - def _visit_importfrom_relative(self, current_package: str, node: nodes.ImportFrom) -> None: + def _visit_importfrom_relative( + self, current_package: str, node: nodes.ImportFrom + ) -> None: """Called when a ImportFrom node is visited.""" - if node.level <= 1 or not current_package.startswith("homeassistant.components"): + if node.level <= 1 or not current_package.startswith( + "homeassistant.components" + ): return split_package = current_package.split(".") if not node.modname and len(split_package) == node.level + 1: @@ -330,7 +334,10 @@ 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": + 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)