Skip to content

Commit

Permalink
chore(ruff) Automated fixes for typing annotations
Browse files Browse the repository at this point in the history
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 .
  • Loading branch information
tony committed Jan 4, 2025
1 parent 7efcd8a commit dd45294
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/vcspull/_internal/config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/vcspull/cli/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
19 changes: 10 additions & 9 deletions src/vcspull/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import pathlib
import typing as t
from collections.abc import Callable

from libvcs.sync.git import GitRemote

Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit dd45294

Please sign in to comment.