diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2b96684d55f..32e06a558c4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -40,7 +40,7 @@ repos: - flake8-comprehensions==3.10.1 - flake8-noqa==1.3.0 - mccabe==0.7.0 - files: ^(homeassistant|script|tests)/.+\.py$ + exclude: docs/source/conf.py - repo: https://github.com/PyCQA/bandit rev: 1.7.4 hooks: diff --git a/docs/source/_ext/edit_on_github.py b/docs/source/_ext/edit_on_github.py index 1d40bfc33ab..420acbbdde5 100644 --- a/docs/source/_ext/edit_on_github.py +++ b/docs/source/_ext/edit_on_github.py @@ -1,6 +1,5 @@ """ -Sphinx extension to add ReadTheDocs-style "Edit on GitHub" links to the -sidebar. +Sphinx extension for ReadTheDocs-style "Edit on GitHub" links on the sidebar. Loosely based on https://github.com/astropy/astropy/pull/347 """ @@ -12,6 +11,7 @@ __licence__ = "BSD (3 clause)" def get_github_url(app, view, path): + """Build the GitHub URL.""" return ( f"https://github.com/{app.config.edit_on_github_project}/" f"{view}/{app.config.edit_on_github_branch}/" @@ -20,6 +20,7 @@ def get_github_url(app, view, path): def html_page_context(app, pagename, templatename, context, doctree): + """Build the HTML page.""" if templatename != "page.html": return @@ -38,6 +39,7 @@ def html_page_context(app, pagename, templatename, context, doctree): def setup(app): + """Set up the app.""" app.add_config_value("edit_on_github_project", "", True) app.add_config_value("edit_on_github_branch", "master", True) app.add_config_value("edit_on_github_src_path", "", True) # 'eg' "docs/" diff --git a/pylint/plugins/hass_constructor.py b/pylint/plugins/hass_constructor.py index 23496b68de3..b2db7ba429b 100644 --- a/pylint/plugins/hass_constructor.py +++ b/pylint/plugins/hass_constructor.py @@ -22,7 +22,7 @@ class HassConstructorFormatChecker(BaseChecker): # type: ignore[misc] options = () def visit_functiondef(self, node: nodes.FunctionDef) -> None: - """Called when a FunctionDef node is visited.""" + """Check for improperly typed `__init__` definitions.""" if not node.is_method() or node.name != "__init__": return diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index 7d97704e675..0ecf9f58398 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -20,7 +20,7 @@ if TYPE_CHECKING: class _Special(Enum): - """Sentinel values""" + """Sentinel values.""" UNDEFINED = 1 @@ -2837,7 +2837,7 @@ def _has_valid_annotations( def _get_module_platform(module_name: str) -> str | None: - """Called when a Module node is visited.""" + """Return the platform for the module name.""" if not (module_match := _MODULE_REGEX.match(module_name)): # Ensure `homeassistant.components.` # Or `homeassistant.components..` @@ -2878,12 +2878,13 @@ class HassTypeHintChecker(BaseChecker): # type: ignore[misc] ) def __init__(self, linter: PyLinter | None = None) -> None: + """Initialize the HassTypeHintChecker.""" super().__init__(linter) self._function_matchers: list[TypeHintMatch] = [] self._class_matchers: list[ClassTypeHintMatch] = [] def visit_module(self, node: nodes.Module) -> None: - """Called when a Module node is visited.""" + """Populate matchers for a Module node.""" self._function_matchers = [] self._class_matchers = [] @@ -2907,7 +2908,7 @@ class HassTypeHintChecker(BaseChecker): # type: ignore[misc] self._class_matchers.reverse() def visit_classdef(self, node: nodes.ClassDef) -> None: - """Called when a ClassDef node is visited.""" + """Apply relevant type hint checks on a ClassDef node.""" ancestor: nodes.ClassDef checked_class_methods: set[str] = set() ancestors = list(node.ancestors()) # cache result for inside loop @@ -2934,7 +2935,7 @@ class HassTypeHintChecker(BaseChecker): # type: ignore[misc] checked_class_methods.add(function_node.name) def visit_functiondef(self, node: nodes.FunctionDef) -> None: - """Called when a FunctionDef node is visited.""" + """Apply relevant type hint checks on a FunctionDef node.""" for match in self._function_matchers: if not match.need_to_check_function(node) or node.is_method(): continue diff --git a/pylint/plugins/hass_imports.py b/pylint/plugins/hass_imports.py index 0a9291ec5ec..6bde2193b59 100644 --- a/pylint/plugins/hass_imports.py +++ b/pylint/plugins/hass_imports.py @@ -396,11 +396,12 @@ class HassImportsFormatChecker(BaseChecker): # type: ignore[misc] options = () def __init__(self, linter: PyLinter | None = None) -> None: + """Initialize the HassImportsFormatChecker.""" super().__init__(linter) self.current_package: str | None = None def visit_module(self, node: nodes.Module) -> None: - """Called when a Module node is visited.""" + """Determine current package.""" if node.package: self.current_package = node.name else: @@ -408,7 +409,7 @@ class HassImportsFormatChecker(BaseChecker): # type: ignore[misc] self.current_package = node.name[: node.name.rfind(".")] def visit_import(self, node: nodes.Import) -> None: - """Called when a Import node is visited.""" + """Check for improper `import _` invocations.""" if self.current_package is None: return for module, _alias in node.names: @@ -430,7 +431,7 @@ class HassImportsFormatChecker(BaseChecker): # type: ignore[misc] def _visit_importfrom_relative( self, current_package: str, node: nodes.ImportFrom ) -> None: - """Called when a ImportFrom node is visited.""" + """Check for improper 'from ._ import _' invocations.""" if ( node.level <= 1 or not current_package.startswith("homeassistant.components.") @@ -449,7 +450,7 @@ class HassImportsFormatChecker(BaseChecker): # type: ignore[misc] self.add_message("hass-absolute-import", node=node) def visit_importfrom(self, node: nodes.ImportFrom) -> None: - """Called when a ImportFrom node is visited.""" + """Check for improper 'from _ import _' invocations.""" if not self.current_package: return if node.level is not None: diff --git a/pylint/plugins/hass_logger.py b/pylint/plugins/hass_logger.py index 0135720a792..bfa05001304 100644 --- a/pylint/plugins/hass_logger.py +++ b/pylint/plugins/hass_logger.py @@ -29,13 +29,13 @@ class HassLoggerFormatChecker(BaseChecker): # type: ignore[misc] options = () def visit_call(self, node: nodes.Call) -> None: - """Called when a Call node is visited.""" + """Check for improper log messages.""" if not isinstance(node.func, nodes.Attribute) or not isinstance( node.func.expr, nodes.Name ): return - if not node.func.expr.name in LOGGER_NAMES: + if node.func.expr.name not in LOGGER_NAMES: return if not node.args: