Skip to content

Commit ffbe335

Browse files
committed
!squash typings
1 parent 45d6f73 commit ffbe335

File tree

13 files changed

+120
-59
lines changed

13 files changed

+120
-59
lines changed

conftest.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,36 +34,40 @@ def cwd_default(monkeypatch: pytest.MonkeyPatch, tmp_path: pathlib.Path) -> None
3434

3535
@pytest.fixture(autouse=True, scope="session")
3636
@pytest.mark.usefixtures("set_home")
37-
def xdg_config_path(user_path: pathlib.Path):
37+
def xdg_config_path(user_path: pathlib.Path) -> pathlib.Path:
3838
p = user_path / ".config"
3939
p.mkdir()
4040
return p
4141

4242

4343
@pytest.fixture(scope="function")
44-
def config_path(xdg_config_path: pathlib.Path, request: pytest.FixtureRequest):
44+
def config_path(
45+
xdg_config_path: pathlib.Path, request: pytest.FixtureRequest
46+
) -> pathlib.Path:
4547
conf_path = xdg_config_path / "vcspull"
4648
conf_path.mkdir(exist_ok=True)
4749

48-
def clean():
50+
def clean() -> None:
4951
shutil.rmtree(conf_path)
5052

5153
request.addfinalizer(clean)
5254
return conf_path
5355

5456

5557
@pytest.fixture(autouse=True)
56-
def set_xdg_config_path(monkeypatch: pytest.MonkeyPatch, xdg_config_path: pathlib.Path):
58+
def set_xdg_config_path(
59+
monkeypatch: pytest.MonkeyPatch, xdg_config_path: pathlib.Path
60+
) -> None:
5761
monkeypatch.setenv("XDG_CONFIG_HOME", str(xdg_config_path))
5862

5963

6064
@pytest.fixture(scope="function")
61-
def repos_path(user_path: pathlib.Path, request: pytest.FixtureRequest):
65+
def repos_path(user_path: pathlib.Path, request: pytest.FixtureRequest) -> pathlib.Path:
6266
"""Return temporary directory for repository checkout guaranteed unique."""
6367
dir = user_path / "repos"
6468
dir.mkdir(exist_ok=True)
6569

66-
def clean():
70+
def clean() -> None:
6771
shutil.rmtree(dir)
6872

6973
request.addfinalizer(clean)

src/vcspull/cli/__init__.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import argparse
88
import logging
99
import textwrap
10+
import typing as t
11+
from typing import overload
1012

1113
from libvcs.__about__ import __version__ as libvcs_version
1214

@@ -30,7 +32,19 @@
3032
).strip()
3133

3234

33-
def create_parser(return_subparsers: bool = False):
35+
@overload
36+
def create_parser(
37+
return_subparsers: t.Literal[True],
38+
) -> t.Tuple[argparse.ArgumentParser, t.Any]:
39+
...
40+
41+
42+
@overload
43+
def create_parser(return_subparsers: t.Literal[False]) -> argparse.ArgumentParser:
44+
...
45+
46+
47+
def create_parser(return_subparsers: bool = False) -> argparse.ArgumentParser:
3448
parser = argparse.ArgumentParser(
3549
prog="vcspull",
3650
formatter_class=argparse.RawDescriptionHelpFormatter,
@@ -64,9 +78,9 @@ def create_parser(return_subparsers: bool = False):
6478
return parser
6579

6680

67-
def cli(args=None):
81+
def cli(_args: t.Optional[t.List[str]] = None) -> None:
6882
parser, sync_parser = create_parser(return_subparsers=True)
69-
args = parser.parse_args(args)
83+
args = parser.parse_args(_args)
7084

7185
setup_logger(log=log, level=args.log_level.upper())
7286

src/vcspull/cli/sync.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import sys
44
import typing as t
55
from copy import deepcopy
6+
from datetime import datetime
67

78
from libvcs._internal.shortcuts import create_project
9+
from libvcs.sync.git import GitSync
810
from libvcs.url import registry as url_tools
911

1012
from ..config import filter_repos, find_config_files, load_configs
@@ -102,12 +104,15 @@ def sync(
102104
raise SystemExit(EXIT_ON_ERROR_MSG)
103105

104106

105-
def progress_cb(output, timestamp):
107+
def progress_cb(output: str, timestamp: datetime) -> None:
106108
sys.stdout.write(output)
107109
sys.stdout.flush()
108110

109111

110-
def update_repo(repo_dict):
112+
def update_repo(
113+
repo_dict: t.Any,
114+
# repo_dict: Dict[str, Union[str, Dict[str, GitRemote], pathlib.Path]]
115+
) -> GitSync:
111116
repo_dict = deepcopy(repo_dict)
112117
if "pip_url" not in repo_dict:
113118
repo_dict["pip_url"] = repo_dict.pop("url")

src/vcspull/config.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ def expand_dir(
4949
return _dir
5050

5151

52-
def extract_repos(config: RawConfigDict, cwd=pathlib.Path.cwd()) -> list[ConfigDict]:
52+
def extract_repos(
53+
config: RawConfigDict, cwd: pathlib.Path = pathlib.Path.cwd()
54+
) -> list[ConfigDict]:
5355
"""Return expanded configuration.
5456
5557
end-user configuration permit inline configuration shortcuts, expand to
@@ -165,7 +167,7 @@ def find_config_files(
165167
t.Literal["json", "yaml", "*"], list[t.Literal["json", "yaml", "*"]]
166168
] = ["json", "yaml"],
167169
include_home: bool = False,
168-
):
170+
) -> t.List[t.Union[t.Any, pathlib.Path]]:
169171
"""Return repos from a directory and match. Not recursive.
170172
171173
Parameters
@@ -216,7 +218,9 @@ def find_config_files(
216218
return configs
217219

218220

219-
def load_configs(files: list[StrPath], cwd=pathlib.Path.cwd()):
221+
def load_configs(
222+
files: list[StrPath], cwd: pathlib.Path = pathlib.Path.cwd()
223+
) -> t.List[t.Dict[str, t.Union[str, t.Dict[str, GitRemote], pathlib.Path]]]:
220224
"""Return repos from a list of files.
221225
222226
Parameters
@@ -295,7 +299,10 @@ def detect_duplicate_repos(
295299
return dupes
296300

297301

298-
def in_dir(config_dir=None, extensions: list[str] = [".yml", ".yaml", ".json"]):
302+
def in_dir(
303+
config_dir: t.Optional[str] = None,
304+
extensions: list[str] = [".yml", ".yaml", ".json"],
305+
) -> t.List[str]:
299306
"""Return a list of configs in ``config_dir``.
300307
301308
Parameters

src/vcspull/util.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
import os
88
import pathlib
9+
import typing as t
910
from collections.abc import Mapping
1011

1112
LEGACY_CONFIG_DIR = os.path.expanduser("~/.vcspull/") # remove dupes of this
@@ -45,7 +46,10 @@ def get_config_dir() -> pathlib.Path:
4546
return pathlib.Path(path)
4647

4748

48-
def update_dict(d, u):
49+
def update_dict(
50+
d: t.Dict[t.Any, t.Any],
51+
u: t.Mapping[str, t.Union[str, t.Dict[str, str], t.List[str]]],
52+
) -> t.Dict[str, t.Union[str, t.Dict[str, str], t.List[str]]]:
4953
"""Return updated dict.
5054
5155
Parameters

tests/fixtures/_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
22

33

4-
def curjoin(_file): # return filepath relative to __file__ (this file)
4+
def curjoin(_file: str) -> str: # return filepath relative to __file__ (this file)
55
return os.path.join(os.path.dirname(__file__), _file)

tests/helpers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ class EnvironmentVarGuard:
1515
including test module, see #121.
1616
"""
1717

18-
def __init__(self):
18+
def __init__(self) -> None:
1919
self._environ = os.environ
2020
self._unset = set()
2121
self._reset = dict()
2222

23-
def set(self, envvar, value):
23+
def set(self, envvar: str, value: str) -> None:
2424
if envvar not in self._environ:
2525
self._unset.add(envvar)
2626
else:
@@ -32,10 +32,10 @@ def unset(self, envvar):
3232
self._reset[envvar] = self._environ[envvar]
3333
del self._environ[envvar]
3434

35-
def __enter__(self):
35+
def __enter__(self) -> "EnvironmentVarGuard":
3636
return self
3737

38-
def __exit__(self, *ignore_exc):
38+
def __exit__(self, *ignore_exc) -> None:
3939
for envvar, value in self._reset.items():
4040
self._environ[envvar] = value
4141
for unset in self._unset:

tests/test_cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class SyncCLINonExistentRepo(t.NamedTuple):
6161
)
6262
def test_sync_cli_filter_non_existent(
6363
tmp_path: pathlib.Path,
64-
capsys: pytest.CaptureFixture,
64+
capsys: pytest.CaptureFixture[str],
6565
monkeypatch: pytest.MonkeyPatch,
6666
user_path: pathlib.Path,
6767
config_path: pathlib.Path,
@@ -192,7 +192,7 @@ class SyncFixture(t.NamedTuple):
192192
)
193193
def test_sync(
194194
tmp_path: pathlib.Path,
195-
capsys: pytest.CaptureFixture,
195+
capsys: pytest.CaptureFixture[str],
196196
monkeypatch: pytest.MonkeyPatch,
197197
user_path: pathlib.Path,
198198
config_path: pathlib.Path,
@@ -324,7 +324,7 @@ class SyncBrokenFixture(t.NamedTuple):
324324
)
325325
def test_sync_broken(
326326
tmp_path: pathlib.Path,
327-
capsys: pytest.CaptureFixture,
327+
capsys: pytest.CaptureFixture[str],
328328
monkeypatch: pytest.MonkeyPatch,
329329
user_path: pathlib.Path,
330330
config_path: pathlib.Path,

tests/test_config.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
import pathlib
2+
import typing as t
3+
from typing import Callable
24

35
import pytest
46

57
from vcspull import config
68

79

10+
class LoadYAMLFn(t.Protocol):
11+
def __call__(
12+
self,
13+
content: str,
14+
dir: str = "randomdir",
15+
filename: str = "randomfilename.yaml",
16+
) -> t.Tuple[
17+
pathlib.Path, t.List[t.Union[t.Any, pathlib.Path]], t.List[t.Dict[str, t.Any]]
18+
]:
19+
...
20+
21+
822
@pytest.fixture
9-
def load_yaml(tmp_path: pathlib.Path):
10-
def fn(content, dir="randomdir", filename="randomfilename.yaml"):
23+
def load_yaml(tmp_path: pathlib.Path) -> LoadYAMLFn:
24+
def fn(content: str, dir: str = "randomdir", filename: str = "randomfilename.yaml"):
1125
_dir = tmp_path / dir
1226
_dir.mkdir()
1327
_config = _dir / filename
@@ -20,7 +34,7 @@ def fn(content, dir="randomdir", filename="randomfilename.yaml"):
2034
return fn
2135

2236

23-
def test_simple_format(load_yaml):
37+
def test_simple_format(load_yaml: LoadYAMLFn) -> None:
2438
dir, _, repos = load_yaml(
2539
"""
2640
vcspull:
@@ -35,7 +49,7 @@ def test_simple_format(load_yaml):
3549
assert dir / "vcspull" / "libvcs" == repo["dir"]
3650

3751

38-
def test_relative_dir(load_yaml):
52+
def test_relative_dir(load_yaml: LoadYAMLFn) -> None:
3953
dir, _, repos = load_yaml(
4054
"""
4155
./relativedir:

0 commit comments

Comments
 (0)