Skip to content

Commit bbf0028

Browse files
committed
chore(ruff) Automated fixes for typing annotations
Fixed 134 errors: - conftest.py: 1 × TC003 (typing-only-standard-library-import) 1 × I002 (missing-required-import) - docs/conf.py: 2 × UP037 (quoted-annotation) 1 × I002 (missing-required-import) 1 × I001 (unsorted-imports) 1 × UP007 (non-pep604-annotation) - scripts/generate_gitlab.py: 1 × I001 (unsorted-imports) 1 × TC001 (typing-only-first-party-import) 1 × I002 (missing-required-import) - src/vcspull/__about__.py: 1 × I002 (missing-required-import) - src/vcspull/__init__.py: 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - src/vcspull/_internal/config_reader.py: 8 × UP037 (quoted-annotation) 1 × I001 (unsorted-imports) 1 × I002 (missing-required-import) - src/vcspull/cli/__init__.py: 2 × UP007 (non-pep604-annotation) 1 × I002 (missing-required-import) - src/vcspull/cli/sync.py: 3 × TC003 (typing-only-standard-library-import) 2 × UP007 (non-pep604-annotation) 2 × TC002 (typing-only-third-party-import) 1 × I002 (missing-required-import) 1 × I001 (unsorted-imports) - src/vcspull/config.py: 17 × UP007 (non-pep604-annotation) 8 × UP037 (quoted-annotation) 1 × I002 (missing-required-import) 1 × TC003 (typing-only-standard-library-import) 1 × I001 (unsorted-imports) - src/vcspull/exc.py: 1 × I002 (missing-required-import) - src/vcspull/log.py: 1 × UP007 (non-pep604-annotation) 1 × I002 (missing-required-import) - src/vcspull/types.py: 3 × UP007 (non-pep604-annotation) 3 × TC002 (typing-only-third-party-import) 1 × TC003 (typing-only-standard-library-import) 1 × I002 (missing-required-import) 1 × I001 (unsorted-imports) - src/vcspull/util.py: 1 × I002 (missing-required-import) - src/vcspull/validator.py: 1 × I002 (missing-required-import) 1 × UP037 (quoted-annotation) - tests/__init__.py: 1 × I002 (missing-required-import) - tests/fixtures/example.py: 1 × I002 (missing-required-import) 1 × UP037 (quoted-annotation) - tests/helpers.py: 1 × UP037 (quoted-annotation) 1 × TC003 (typing-only-standard-library-import) 1 × I002 (missing-required-import) 1 × I001 (unsorted-imports) 1 × PYI034 (non-self-return-type) - tests/test_cli.py: 24 × UP037 (quoted-annotation) 1 × TC003 (typing-only-standard-library-import) 1 × I002 (missing-required-import) 1 × TC002 (typing-only-third-party-import) 1 × I001 (unsorted-imports) - tests/test_config.py: 2 × UP037 (quoted-annotation) 1 × I002 (missing-required-import) 1 × UP007 (non-pep604-annotation) 1 × TC003 (typing-only-standard-library-import) 1 × I001 (unsorted-imports) - tests/test_config_file.py: 1 × I002 (missing-required-import) - tests/test_repo.py: 1 × I001 (unsorted-imports) 1 × TC003 (typing-only-standard-library-import) 1 × I002 (missing-required-import) - tests/test_sync.py: 1 × I002 (missing-required-import) 1 × TC003 (typing-only-standard-library-import) 1 × TC002 (typing-only-third-party-import) 1 × I001 (unsorted-imports) - tests/test_utils.py: 3 × I001 (unsorted-imports) 1 × TC003 (typing-only-standard-library-import) 1 × I002 (missing-required-import) 1 × TC002 (typing-only-third-party-import) Found 460 errors (134 fixed, 326 remaining). 20 files reformatted, 5 files left unchanged uv run ruff check --select ALL . --fix --unsafe-fixes --preview --show-fixes; uv run ruff format .
1 parent c339479 commit bbf0028

23 files changed

+163
-92
lines changed

conftest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
https://docs.pytest.org/en/stable/deprecations.html
99
"""
1010

11-
import pathlib
11+
from __future__ import annotations
12+
1213
import shutil
1314
import typing as t
1415

1516
import pytest
1617

18+
if t.TYPE_CHECKING:
19+
import pathlib
20+
1721

1822
@pytest.fixture(autouse=True)
1923
def add_doctest_fixtures(

docs/conf.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Sphinx configuration for vcspull documentation."""
22

33
# flake8: noqa: E501
4+
from __future__ import annotations
5+
46
import inspect
57
import pathlib
68
import sys
@@ -146,7 +148,7 @@
146148
}
147149

148150

149-
def linkcode_resolve(domain: str, info: dict[str, str]) -> t.Union[None, str]:
151+
def linkcode_resolve(domain: str, info: dict[str, str]) -> None | str:
150152
"""
151153
Determine the URL corresponding to Python object.
152154
@@ -216,13 +218,13 @@ def linkcode_resolve(domain: str, info: dict[str, str]) -> t.Union[None, str]:
216218
)
217219

218220

219-
def remove_tabs_js(app: "Sphinx", exc: Exception) -> None:
221+
def remove_tabs_js(app: Sphinx, exc: Exception) -> None:
220222
"""Fix for sphinx-inline-tabs#18."""
221223
if app.builder.format == "html" and not exc:
222224
tabs_js = pathlib.Path(app.builder.outdir) / "_static" / "tabs.js"
223225
tabs_js.unlink(missing_ok=True)
224226

225227

226-
def setup(app: "Sphinx") -> None:
228+
def setup(app: Sphinx) -> None:
227229
"""Sphinx setup hook."""
228230
app.connect("build-finished", remove_tabs_js)

scripts/generate_gitlab.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
#!/usr/bin/env python
22
"""Example script for export gitlab organization to vcspull config file."""
33

4+
from __future__ import annotations
5+
46
import argparse
57
import logging
68
import os
79
import pathlib
810
import sys
11+
from typing import TYPE_CHECKING
912

1013
import requests
1114
import yaml
1215
from libvcs.sync.git import GitRemote
1316

1417
from vcspull.cli.sync import CouldNotGuessVCSFromURL, guess_vcs
15-
from vcspull.types import RawConfig
18+
19+
if TYPE_CHECKING:
20+
from vcspull.types import RawConfig
1621

1722
log = logging.getLogger(__name__)
1823
logging.basicConfig(level=logging.INFO, format="%(message)s")

src/vcspull/__about__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Metadata for vcspull."""
22

3+
from __future__ import annotations
4+
35
__title__ = "vcspull"
46
__package_name__ = "vcspull"
57
__description__ = "Manage and sync multiple git, mercurial, and svn repos"

src/vcspull/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"""
77

88
# Set default logging handler to avoid "No handler found" warnings.
9+
from __future__ import annotations
10+
911
import logging
1012
from logging import NullHandler
1113

src/vcspull/_internal/config_reader.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import json
24
import pathlib
35
import typing as t
@@ -22,11 +24,11 @@ class ConfigReader:
2224
'{\n "session_name": "my session"\n}'
2325
"""
2426

25-
def __init__(self, content: "RawConfigData") -> None:
27+
def __init__(self, content: RawConfigData) -> None:
2628
self.content = content
2729

2830
@staticmethod
29-
def _load(fmt: "FormatLiteral", content: str) -> dict[str, t.Any]:
31+
def _load(fmt: FormatLiteral, content: str) -> dict[str, t.Any]:
3032
"""Load raw config data and directly return it.
3133
3234
>>> ConfigReader._load("json", '{ "session_name": "my session" }')
@@ -49,7 +51,7 @@ def _load(fmt: "FormatLiteral", content: str) -> dict[str, t.Any]:
4951
raise NotImplementedError(msg)
5052

5153
@classmethod
52-
def load(cls, fmt: "FormatLiteral", content: str) -> "ConfigReader":
54+
def load(cls, fmt: FormatLiteral, content: str) -> ConfigReader:
5355
"""Load raw config data into a ConfigReader instance (to dump later).
5456
5557
>>> cfg = ConfigReader.load("json", '{ "session_name": "my session" }')
@@ -118,7 +120,7 @@ def _from_file(cls, path: pathlib.Path) -> dict[str, t.Any]:
118120
)
119121

120122
@classmethod
121-
def from_file(cls, path: pathlib.Path) -> "ConfigReader":
123+
def from_file(cls, path: pathlib.Path) -> ConfigReader:
122124
r"""Load data from file path.
123125
124126
**YAML file**
@@ -159,8 +161,8 @@ def from_file(cls, path: pathlib.Path) -> "ConfigReader":
159161

160162
@staticmethod
161163
def _dump(
162-
fmt: "FormatLiteral",
163-
content: "RawConfigData",
164+
fmt: FormatLiteral,
165+
content: RawConfigData,
164166
indent: int = 2,
165167
**kwargs: t.Any,
166168
) -> str:
@@ -187,7 +189,7 @@ def _dump(
187189
msg = f"{fmt} not supported in config"
188190
raise NotImplementedError(msg)
189191

190-
def dump(self, fmt: "FormatLiteral", indent: int = 2, **kwargs: t.Any) -> str:
192+
def dump(self, fmt: FormatLiteral, indent: int = 2, **kwargs: t.Any) -> str:
191193
r"""Dump via ConfigReader instance.
192194
193195
>>> cfg = ConfigReader({ "session_name": "my session" })

src/vcspull/cli/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""CLI utilities for vcspull."""
22

3+
from __future__ import annotations
4+
35
import argparse
46
import logging
57
import textwrap
@@ -41,7 +43,7 @@ def create_parser(return_subparsers: t.Literal[False]) -> argparse.ArgumentParse
4143

4244
def create_parser(
4345
return_subparsers: bool = False,
44-
) -> t.Union[argparse.ArgumentParser, tuple[argparse.ArgumentParser, t.Any]]:
46+
) -> argparse.ArgumentParser | tuple[argparse.ArgumentParser, t.Any]:
4547
"""Create CLI argument parser for vcspull."""
4648
parser = argparse.ArgumentParser(
4749
prog="vcspull",
@@ -76,7 +78,7 @@ def create_parser(
7678
return parser
7779

7880

79-
def cli(_args: t.Optional[list[str]] = None) -> None:
81+
def cli(_args: list[str] | None = None) -> None:
8082
"""CLI entry point for vcspull."""
8183
parser, sync_parser = create_parser(return_subparsers=True)
8284
args = parser.parse_args(_args)

src/vcspull/cli/sync.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
"""Synchronization functionality for vcspull."""
22

3-
import argparse
3+
from __future__ import annotations
4+
45
import logging
5-
import pathlib
66
import sys
77
import typing as t
88
from copy import deepcopy
9-
from datetime import datetime
109

1110
from libvcs._internal.shortcuts import create_project
12-
from libvcs._internal.types import VCSLiteral
13-
from libvcs.sync.git import GitSync
1411
from libvcs.url import registry as url_tools
1512

1613
from vcspull import exc
1714
from vcspull.config import filter_repos, find_config_files, load_configs
1815

16+
if t.TYPE_CHECKING:
17+
import argparse
18+
import pathlib
19+
from datetime import datetime
20+
21+
from libvcs._internal.types import VCSLiteral
22+
from libvcs.sync.git import GitSync
23+
1924
log = logging.getLogger(__name__)
2025

2126

@@ -63,9 +68,8 @@ def sync(
6368
repo_patterns: list[str],
6469
config: pathlib.Path,
6570
exit_on_error: bool,
66-
parser: t.Optional[
67-
argparse.ArgumentParser
68-
] = None, # optional so sync can be unit tested
71+
parser: argparse.ArgumentParser
72+
| None = None, # optional so sync can be unit tested
6973
) -> None:
7074
"""Entry point for ``vcspull sync``."""
7175
if isinstance(repo_patterns, list) and len(repo_patterns) == 0:
@@ -117,7 +121,7 @@ def progress_cb(output: str, timestamp: datetime) -> None:
117121
sys.stdout.flush()
118122

119123

120-
def guess_vcs(url: str) -> t.Optional[VCSLiteral]:
124+
def guess_vcs(url: str) -> VCSLiteral | None:
121125
"""Guess the VCS from a URL."""
122126
vcs_matches = url_tools.registry.match(url=url, is_explicit=True)
123127

src/vcspull/config.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
"""Configuration functionality for vcspull."""
22

3+
from __future__ import annotations
4+
35
import fnmatch
46
import logging
57
import os
68
import pathlib
79
import typing as t
8-
from collections.abc import Callable
910

1011
from libvcs.sync.git import GitRemote
1112

@@ -18,14 +19,16 @@
1819
log = logging.getLogger(__name__)
1920

2021
if t.TYPE_CHECKING:
22+
from collections.abc import Callable
23+
2124
from typing_extensions import TypeGuard
2225

2326
from .types import ConfigDict, RawConfigDict
2427

2528

2629
def expand_dir(
2730
dir_: pathlib.Path,
28-
cwd: t.Union[pathlib.Path, Callable[[], pathlib.Path]] = pathlib.Path.cwd,
31+
cwd: pathlib.Path | Callable[[], pathlib.Path] = pathlib.Path.cwd,
2932
) -> pathlib.Path:
3033
"""Return path with environmental variables and tilde ~ expanded.
3134
@@ -52,9 +55,9 @@ def expand_dir(
5255

5356

5457
def extract_repos(
55-
config: "RawConfigDict",
56-
cwd: t.Union[pathlib.Path, Callable[[], pathlib.Path]] = pathlib.Path.cwd,
57-
) -> list["ConfigDict"]:
58+
config: RawConfigDict,
59+
cwd: pathlib.Path | Callable[[], pathlib.Path] = pathlib.Path.cwd,
60+
) -> list[ConfigDict]:
5861
"""Return expanded configuration.
5962
6063
end-user configuration permit inline configuration shortcuts, expand to
@@ -130,7 +133,7 @@ def extract_repos(
130133
**url,
131134
)
132135

133-
def is_valid_config_dict(val: t.Any) -> "TypeGuard[ConfigDict]":
136+
def is_valid_config_dict(val: t.Any) -> TypeGuard[ConfigDict]:
134137
assert isinstance(val, dict)
135138
return True
136139

@@ -142,7 +145,7 @@ def is_valid_config_dict(val: t.Any) -> "TypeGuard[ConfigDict]":
142145

143146

144147
def find_home_config_files(
145-
filetype: t.Optional[list[str]] = None,
148+
filetype: list[str] | None = None,
146149
) -> list[pathlib.Path]:
147150
"""Return configs of ``.vcspull.{yaml,json}`` in user's home directory."""
148151
if filetype is None:
@@ -172,11 +175,11 @@ def find_home_config_files(
172175

173176

174177
def find_config_files(
175-
path: t.Optional[t.Union[list[pathlib.Path], pathlib.Path]] = None,
176-
match: t.Optional[t.Union[list[str], str]] = None,
177-
filetype: t.Optional[
178-
t.Union[t.Literal["json", "yaml", "*"], list[t.Literal["json", "yaml", "*"]]]
179-
] = None,
178+
path: list[pathlib.Path] | pathlib.Path | None = None,
179+
match: list[str] | str | None = None,
180+
filetype: t.Literal["json", "yaml", "*"]
181+
| list[t.Literal["json", "yaml", "*"]]
182+
| None = None,
180183
include_home: bool = False,
181184
) -> list[pathlib.Path]:
182185
"""Return repos from a directory and match. Not recursive.
@@ -234,8 +237,8 @@ def find_config_files(
234237

235238
def load_configs(
236239
files: list[pathlib.Path],
237-
cwd: t.Union[pathlib.Path, Callable[[], pathlib.Path]] = pathlib.Path.cwd,
238-
) -> list["ConfigDict"]:
240+
cwd: pathlib.Path | Callable[[], pathlib.Path] = pathlib.Path.cwd,
241+
) -> list[ConfigDict]:
239242
"""Return repos from a list of files.
240243
241244
Parameters
@@ -284,8 +287,8 @@ def load_configs(
284287

285288

286289
def detect_duplicate_repos(
287-
config1: list["ConfigDict"],
288-
config2: list["ConfigDict"],
290+
config1: list[ConfigDict],
291+
config2: list[ConfigDict],
289292
) -> list[ConfigDictTuple]:
290293
"""Return duplicate repos dict if repo_dir same and vcs different.
291294
@@ -320,8 +323,8 @@ def detect_duplicate_repos(
320323

321324

322325
def in_dir(
323-
config_dir: t.Optional[pathlib.Path] = None,
324-
extensions: t.Optional[list[str]] = None,
326+
config_dir: pathlib.Path | None = None,
327+
extensions: list[str] | None = None,
325328
) -> list[str]:
326329
"""Return a list of configs in ``config_dir``.
327330
@@ -349,11 +352,11 @@ def in_dir(
349352

350353

351354
def filter_repos(
352-
config: list["ConfigDict"],
353-
path: t.Union[pathlib.Path, t.Literal["*"], str, None] = None,
354-
vcs_url: t.Union[str, None] = None,
355-
name: t.Union[str, None] = None,
356-
) -> list["ConfigDict"]:
355+
config: list[ConfigDict],
356+
path: pathlib.Path | t.Literal["*"] | str | None = None,
357+
vcs_url: str | None = None,
358+
name: str | None = None,
359+
) -> list[ConfigDict]:
357360
"""Return a :py:obj:`list` list of repos from (expanded) config file.
358361
359362
path, vcs_url and name all support fnmatch.
@@ -402,7 +405,7 @@ def filter_repos(
402405

403406
def is_config_file(
404407
filename: str,
405-
extensions: t.Optional[t.Union[list[str], str]] = None,
408+
extensions: list[str] | str | None = None,
406409
) -> bool:
407410
"""Return True if file has a valid config file type.
408411

src/vcspull/exc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Exceptions for vcspull."""
22

3+
from __future__ import annotations
4+
35

46
class VCSPullException(Exception):
57
"""Standard exception raised by vcspull."""

0 commit comments

Comments
 (0)