From dd45294807eefea44bf0a2744b5db41bc03ff45d Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 4 Jan 2025 06:21:48 -0600 Subject: [PATCH] chore(ruff) Automated fixes for typing annotations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed 11 errors: - src/vcspull/_internal/config_reader.py: 2 × TC006 (runtime-cast-value) - src/vcspull/cli/sync.py: 1 × TC006 (runtime-cast-value) - src/vcspull/config.py: 3 × UP006 (non-pep585-annotation) 2 × RUF052 (used-dummy-variable) 1 × I001 (unsorted-imports) - tests/test_config.py: 2 × RUF052 (used-dummy-variable) Found 362 errors (11 fixed, 351 remaining). 25 files left unchanged uv run ruff check --select ALL . --fix --unsafe-fixes --preview --show-fixes; uv run ruff format . --- src/vcspull/_internal/config_reader.py | 4 ++-- src/vcspull/cli/sync.py | 2 +- src/vcspull/config.py | 19 ++++++++++--------- tests/test_config.py | 16 ++++++++-------- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/vcspull/_internal/config_reader.py b/src/vcspull/_internal/config_reader.py index f5baf6c8..f51dbc8c 100644 --- a/src/vcspull/_internal/config_reader.py +++ b/src/vcspull/_internal/config_reader.py @@ -37,14 +37,14 @@ def _load(fmt: "FormatLiteral", content: str) -> dict[str, t.Any]: """ if fmt == "yaml": return t.cast( - dict[str, t.Any], + "dict[str, t.Any]", yaml.load( content, Loader=yaml.SafeLoader, ), ) if fmt == "json": - return t.cast(dict[str, t.Any], json.loads(content)) + return t.cast("dict[str, t.Any]", json.loads(content)) msg = f"{fmt} not supported in configuration" raise NotImplementedError(msg) diff --git a/src/vcspull/cli/sync.py b/src/vcspull/cli/sync.py index 45d61a6f..affdcfd2 100644 --- a/src/vcspull/cli/sync.py +++ b/src/vcspull/cli/sync.py @@ -128,7 +128,7 @@ def guess_vcs(url: str) -> t.Optional[VCSLiteral]: log.warning(f"No exact matches for {url}") return None - return t.cast(VCSLiteral, vcs_matches[0].vcs) + return t.cast("VCSLiteral", vcs_matches[0].vcs) class CouldNotGuessVCSFromURL(exc.VCSPullException): diff --git a/src/vcspull/config.py b/src/vcspull/config.py index 77d7cc78..18a35cc5 100644 --- a/src/vcspull/config.py +++ b/src/vcspull/config.py @@ -5,6 +5,7 @@ import os import pathlib import typing as t +from collections.abc import Callable from libvcs.sync.git import GitRemote @@ -23,8 +24,8 @@ def expand_dir( - _dir: pathlib.Path, - cwd: t.Union[pathlib.Path, t.Callable[[], pathlib.Path]] = pathlib.Path.cwd, + dir_: pathlib.Path, + cwd: t.Union[pathlib.Path, Callable[[], pathlib.Path]] = pathlib.Path.cwd, ) -> pathlib.Path: """Return path with environmental variables and tilde ~ expanded. @@ -40,19 +41,19 @@ def expand_dir( pathlib.Path : Absolute directory path """ - _dir = pathlib.Path(os.path.expandvars(str(_dir))).expanduser() + dir_ = pathlib.Path(os.path.expandvars(str(dir_))).expanduser() if callable(cwd): cwd = cwd() - if not _dir.is_absolute(): - _dir = pathlib.Path(os.path.normpath(cwd / _dir)) - assert _dir == pathlib.Path(cwd, _dir).resolve(strict=False) - return _dir + if not dir_.is_absolute(): + dir_ = pathlib.Path(os.path.normpath(cwd / dir_)) + assert dir_ == pathlib.Path(cwd, dir_).resolve(strict=False) + return dir_ def extract_repos( config: "RawConfigDict", - cwd: t.Union[pathlib.Path, t.Callable[[], pathlib.Path]] = pathlib.Path.cwd, + cwd: t.Union[pathlib.Path, Callable[[], pathlib.Path]] = pathlib.Path.cwd, ) -> list["ConfigDict"]: """Return expanded configuration. @@ -233,7 +234,7 @@ def find_config_files( def load_configs( files: list[pathlib.Path], - cwd: t.Union[pathlib.Path, t.Callable[[], pathlib.Path]] = pathlib.Path.cwd, + cwd: t.Union[pathlib.Path, Callable[[], pathlib.Path]] = pathlib.Path.cwd, ) -> list["ConfigDict"]: """Return repos from a list of files. diff --git a/tests/test_config.py b/tests/test_config.py index 0ed1b9fb..8dfea4d3 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -34,14 +34,14 @@ def fn( filename: str = "randomfilename.yaml", ) -> tuple[pathlib.Path, list[pathlib.Path], list["ConfigDict"]]: """Return vcspull configurations and write out config to temp directory.""" - _dir = tmp_path / path - _dir.mkdir() - _config = _dir / filename - _config.write_text(content, encoding="utf-8") - - configs = config.find_config_files(path=_dir) - repos = config.load_configs(configs, cwd=_dir) - return _dir, configs, repos + dir_ = tmp_path / path + dir_.mkdir() + config_ = dir_ / filename + config_.write_text(content, encoding="utf-8") + + configs = config.find_config_files(path=dir_) + repos = config.load_configs(configs, cwd=dir_) + return dir_, configs, repos return fn