From 4463ebbe12e239142a624131903d70515e260568 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:14:21 +0100 Subject: [PATCH] MAINT: update lock files (#467) * MAINT: fix Ruff linting errors --- .pre-commit-config.yaml | 10 +++++----- src/compwa_policy/check_dev_files/citation.py | 2 +- src/compwa_policy/check_dev_files/precommit.py | 6 +++--- src/compwa_policy/check_dev_files/readthedocs.py | 11 ++++++----- src/compwa_policy/utilities/executor.py | 6 +++--- src/compwa_policy/utilities/precommit/__init__.py | 6 +++--- src/compwa_policy/utilities/precommit/setters.py | 6 +++--- src/compwa_policy/utilities/precommit/struct.py | 6 +++--- src/compwa_policy/utilities/pyproject/__init__.py | 10 +++++----- src/compwa_policy/utilities/pyproject/_struct.py | 7 +++---- src/compwa_policy/utilities/pyproject/setters.py | 5 +++-- 11 files changed, 38 insertions(+), 37 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c942a86f..19ecf2dd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: - id: check-useless-excludes - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.1 + rev: v0.8.1 hooks: - id: ruff args: [--fix] @@ -61,7 +61,7 @@ repos: files: ^\.pre\-commit\-(config|hooks)\.yaml$ - repo: https://github.com/ComPWA/prettier-pre-commit - rev: v3.3.3 + rev: v3.4.1 hooks: - id: prettier @@ -71,14 +71,14 @@ repos: - id: taplo-format - repo: https://github.com/pappasam/toml-sort - rev: v0.23.1 + rev: v0.24.2 hooks: - id: toml-sort args: [--in-place] exclude: (?x)^(labels/.*\.toml)$ - repo: https://github.com/streetsidesoftware/cspell-cli - rev: v8.15.2 + rev: v8.16.0 hooks: - id: cspell @@ -104,6 +104,6 @@ repos: - python - repo: https://github.com/ComPWA/pyright-pre-commit - rev: v1.1.386 + rev: v1.1.389 hooks: - id: pyright diff --git a/src/compwa_policy/check_dev_files/citation.py b/src/compwa_policy/check_dev_files/citation.py index fb075236..a990344e 100644 --- a/src/compwa_policy/check_dev_files/citation.py +++ b/src/compwa_policy/check_dev_files/citation.py @@ -204,7 +204,7 @@ def add_json_schema_precommit(precommit: ModifiablePrecommit) -> None: else: existing_hooks[hook_idx] = expected_hook existing_repos = precommit.document["repos"] - repos_yaml = cast(CommentedSeq, existing_repos) + repos_yaml = cast("CommentedSeq", existing_repos) repos_yaml.yaml_set_comment_before_after_key(repo_idx + 1, before="\n") msg = f"Updated pre-commit hook {repo_url}" precommit.changelog.append(msg) diff --git a/src/compwa_policy/check_dev_files/precommit.py b/src/compwa_policy/check_dev_files/precommit.py index 158fea39..a1ccdf29 100644 --- a/src/compwa_policy/check_dev_files/precommit.py +++ b/src/compwa_policy/check_dev_files/precommit.py @@ -6,8 +6,6 @@ from pathlib import Path from typing import TYPE_CHECKING, cast -from ruamel.yaml.comments import CommentedMap - from compwa_policy.errors import PrecommitError from compwa_policy.utilities import CONFIG_PATH from compwa_policy.utilities.executor import Executor @@ -17,6 +15,8 @@ from compwa_policy.utilities.yaml import create_prettier_round_trip_yaml if TYPE_CHECKING: + from ruamel.yaml.comments import CommentedMap + from compwa_policy.utilities.precommit import ( ModifiablePrecommit, Precommit, @@ -118,7 +118,7 @@ def _update_precommit_ci_skip(precommit: ModifiablePrecommit) -> None: existing_skips = precommit_ci.get("skip") if existing_skips != expected_skips: precommit_ci["skip"] = sorted(expected_skips) - yaml_config = cast(CommentedMap, precommit.document) + yaml_config = cast("CommentedMap", precommit.document) yaml_config.yaml_set_comment_before_after_key("repos", before="\n") msg = "Updated ci.skip section" precommit.changelog.append(msg) diff --git a/src/compwa_policy/check_dev_files/readthedocs.py b/src/compwa_policy/check_dev_files/readthedocs.py index ebab6fde..28d2ed7c 100644 --- a/src/compwa_policy/check_dev_files/readthedocs.py +++ b/src/compwa_policy/check_dev_files/readthedocs.py @@ -7,7 +7,6 @@ from textwrap import dedent, indent from typing import IO, TYPE_CHECKING, Callable, cast -from ruamel.yaml.comments import CommentedMap from ruamel.yaml.scalarstring import DoubleQuotedScalarString, LiteralScalarString from compwa_policy.errors import PrecommitError @@ -17,6 +16,8 @@ from compwa_policy.utilities.yaml import create_prettier_round_trip_yaml if TYPE_CHECKING: + from ruamel.yaml.comments import CommentedMap + from compwa_policy.check_dev_files.conda import PackageManagerChoice from compwa_policy.utilities.pyproject.getters import PythonVersion @@ -51,7 +52,7 @@ def main( def _update_os(config: ReadTheDocs) -> None: - build = cast(CommentedMap, config.document.get("build")) + build = cast("CommentedMap", config.document.get("build")) if build is None: return os: str | None = build.get("os") @@ -64,7 +65,7 @@ def _update_os(config: ReadTheDocs) -> None: def _update_python_version(config: ReadTheDocs, python_version: PythonVersion) -> None: - tools = cast(CommentedMap, config.document.get("build", {}).get("tools")) + tools = cast("CommentedMap", config.document.get("build", {}).get("tools")) if tools is None: return existing_version: str | None = tools.get("python") @@ -307,9 +308,9 @@ def __init__(self, source: IO | Path | str) -> None: self.source = source if isinstance(source, (Path, str)): with open(source) as f: - self.document = cast(dict, self.__parser.load(f)) + self.document = cast("dict", self.__parser.load(f)) else: - self.document = cast(dict, self.__parser.load(source)) + self.document = cast("dict", self.__parser.load(source)) def dump(self, target: IO | Path | str | None = None) -> None: if target is None: diff --git a/src/compwa_policy/utilities/executor.py b/src/compwa_policy/utilities/executor.py index fe16e8a6..d6568c30 100644 --- a/src/compwa_policy/utilities/executor.py +++ b/src/compwa_policy/utilities/executor.py @@ -24,10 +24,10 @@ from typing import ParamSpec else: from typing_extensions import ParamSpec -if sys.version_info < (3, 11): - from typing_extensions import Self -else: +if sys.version_info >= (3, 11): from typing import Self +else: + from typing_extensions import Self T = TypeVar("T") P = ParamSpec("P") diff --git a/src/compwa_policy/utilities/precommit/__init__.py b/src/compwa_policy/utilities/precommit/__init__.py index 9d829009..1a9cd5a6 100644 --- a/src/compwa_policy/utilities/precommit/__init__.py +++ b/src/compwa_policy/utilities/precommit/__init__.py @@ -19,10 +19,10 @@ ) from compwa_policy.utilities.yaml import create_prettier_round_trip_yaml -if sys.version_info < (3, 11): - from typing_extensions import Self -else: +if sys.version_info >= (3, 11): from typing import Self +else: + from typing_extensions import Self if TYPE_CHECKING: from types import TracebackType diff --git a/src/compwa_policy/utilities/precommit/setters.py b/src/compwa_policy/utilities/precommit/setters.py index 10a9f27a..cc4f2d8c 100644 --- a/src/compwa_policy/utilities/precommit/setters.py +++ b/src/compwa_policy/utilities/precommit/setters.py @@ -64,7 +64,7 @@ def update_single_hook_precommit_repo( expected_yaml.pop("rev", None) expected_yaml.insert(1, "rev", "PLEASE-UPDATE") idx = _determine_expected_repo_index(precommit.document, hook_id) - repos_yaml = cast(CommentedSeq, repos) + repos_yaml = cast("CommentedSeq", repos) repos_yaml.insert(idx, expected_yaml) if isinstance(repos_yaml, CommentedSeq): repos_yaml.yaml_set_comment_before_after_key( @@ -81,7 +81,7 @@ def update_single_hook_precommit_repo( if existing_rev is not None: expected_yaml.insert(1, "rev", PlainScalarString(existing_rev)) repos[idx] = expected_yaml # type: ignore[assignment,call-overload] - repos_map = cast(CommentedMap, repos) + repos_map = cast("CommentedMap", repos) repos_map.yaml_set_comment_before_after_key(idx + 1, before="\n") msg = f"Updated {hook_id} hook" precommit.changelog.append(msg) @@ -126,7 +126,7 @@ def update_precommit_hook( hook_idx = __determine_expected_hook_idx(hooks, expected_hook["id"]) hooks.insert(hook_idx, expected_hook) if hook_idx == len(hooks) - 1: - repos = cast(CommentedMap, precommit.document["repos"][hook_idx]) + repos = cast("CommentedMap", precommit.document["repos"][hook_idx]) repos.yaml_set_comment_before_after_key(repo_idx + 1, before="\n") msg = f"Added {expected_hook['id']!r} to {repo_name} pre-commit config" precommit.changelog.append(msg) diff --git a/src/compwa_policy/utilities/precommit/struct.py b/src/compwa_policy/utilities/precommit/struct.py index 86dc3c44..d65980a5 100644 --- a/src/compwa_policy/utilities/precommit/struct.py +++ b/src/compwa_policy/utilities/precommit/struct.py @@ -5,10 +5,10 @@ from functools import cache from typing import ForwardRef, Literal, TypedDict -if sys.version_info < (3, 11): - from typing_extensions import NotRequired -else: +if sys.version_info >= (3, 11): from typing import NotRequired +else: + from typing_extensions import NotRequired class PrecommitConfig(TypedDict): diff --git a/src/compwa_policy/utilities/pyproject/__init__.py b/src/compwa_policy/utilities/pyproject/__init__.py index 0b4d6c9b..e791a124 100644 --- a/src/compwa_policy/utilities/pyproject/__init__.py +++ b/src/compwa_policy/utilities/pyproject/__init__.py @@ -30,14 +30,14 @@ remove_dependency, ) -if sys.version_info < (3, 11): - from typing_extensions import Self -else: +if sys.version_info >= (3, 11): from typing import Self -if sys.version_info < (3, 12): - from typing_extensions import override else: + from typing_extensions import Self +if sys.version_info >= (3, 12): from typing import override +else: + from typing_extensions import override if TYPE_CHECKING: from collections.abc import Iterable, Mapping, MutableMapping, Sequence from types import TracebackType diff --git a/src/compwa_policy/utilities/pyproject/_struct.py b/src/compwa_policy/utilities/pyproject/_struct.py index 33f79138..54385cb3 100644 --- a/src/compwa_policy/utilities/pyproject/_struct.py +++ b/src/compwa_policy/utilities/pyproject/_struct.py @@ -1,4 +1,3 @@ -# noqa: A005 """This module is hidden Sphinx can't handle `typing.TypedDict` with hyphens. See https://github.com/sphinx-doc/sphinx/issues/11039. @@ -7,10 +6,10 @@ import sys from typing import TypedDict -if sys.version_info < (3, 11): - from typing_extensions import NotRequired -else: +if sys.version_info >= (3, 11): from typing import NotRequired +else: + from typing_extensions import NotRequired IncludeGroup = TypedDict("IncludeGroup", {"include-group": str}) PyprojectTOML = TypedDict( diff --git a/src/compwa_policy/utilities/pyproject/setters.py b/src/compwa_policy/utilities/pyproject/setters.py index 2d8d6249..02cc72a0 100644 --- a/src/compwa_policy/utilities/pyproject/setters.py +++ b/src/compwa_policy/utilities/pyproject/setters.py @@ -5,7 +5,6 @@ import itertools import re from collections import abc -from collections.abc import Iterable, Mapping, MutableMapping, Sequence from typing import TYPE_CHECKING, Any, cast import tomlkit @@ -17,6 +16,8 @@ from compwa_policy.utilities.toml import to_toml_array if TYPE_CHECKING: + from collections.abc import Iterable, Mapping, MutableMapping, Sequence + from tomlkit.items import Table from compwa_policy.utilities.pyproject._struct import IncludeGroup, PyprojectTOML @@ -126,7 +127,7 @@ def get_sub_table( ) -> MutableMapping[str, Any]: create_sub_table(config, dotted_header) table = get_immutable_sub_table(config, dotted_header) - return cast(MutableMapping[str, Any], table) + return cast("MutableMapping[str, Any]", table) def remove_dependency( # noqa: C901, PLR0912