Skip to content
This repository was archived by the owner on Jul 12, 2025. It is now read-only.

Commit 7e56f1e

Browse files
authored
Merge pull request #17 from ewjoachim/strict-pyright
2 parents 165b843 + 69f9c43 commit 7e56f1e

File tree

8 files changed

+44
-28
lines changed

8 files changed

+44
-28
lines changed

poetry_to_pre_commit/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import copy
55
import dataclasses
66
import pathlib
7-
from typing import Any, Generator, Iterable
7+
from typing import Any, Generator, Iterable, cast
88

99
import ruamel.yaml
1010
from poetry import factory
@@ -15,7 +15,7 @@ def pre_commit_config_roundtrip(
1515
path: pathlib.Path,
1616
) -> Generator[dict[str, Any], None, None]:
1717
yaml = ruamel.yaml.YAML()
18-
config = yaml.load(path.read_text())
18+
config = cast("dict[str, Any]", yaml.load(path.read_text()))
1919
old_config = copy.deepcopy(config)
2020
yield config
2121
if config != old_config:

poetry_to_pre_commit/sync_hooks_additional_dependencies.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def format_bind(value: str) -> tuple[str, set[str]]:
2525

2626

2727
def combine_bind_values(bind: list[tuple[str, set[str]]]) -> dict[str, set[str]]:
28-
result = {}
28+
result: dict[str, set[str]] = {}
2929
for key, value in bind:
3030
result.setdefault(key, set()).update(value)
3131
return result
@@ -92,7 +92,7 @@ def update_or_remove_additional_deps(
9292
def _sync_hooks_additional_dependencies(
9393
*,
9494
config: dict[str, Any],
95-
deps_by_group: dict[str, list[str]],
95+
deps_by_group: dict[str, set[str]],
9696
bind: dict[str, set[str]],
9797
no_new_deps: bool = False,
9898
) -> None:
@@ -112,7 +112,7 @@ def _sync_hooks_additional_dependencies(
112112
groups = bind[hook_id]
113113
except KeyError:
114114
continue
115-
deps = set()
115+
deps: set[str] = set()
116116

117117
for group in groups:
118118
deps.update(deps_by_group.get(group, set()))
@@ -137,7 +137,7 @@ def sync_hooks_additional_dependencies(
137137
args = parser.parse_args(argv)
138138

139139
bind = combine_bind_values(args.bind)
140-
deps_by_group = {}
140+
deps_by_group: dict[str, set[str]] = {}
141141

142142
for groups in bind.values():
143143
for group in groups:

poetry_to_pre_commit/sync_repos.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,5 @@ def sync_repos(
126126
)
127127

128128

129-
def sync_repos_cli():
129+
def sync_repos_cli() -> None:
130130
sync_repos(argv=sys.argv[1:])

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ relative_files = true
6666

6767
[tool.pyright]
6868
exclude = ["tests"]
69+
typeCheckingMode = "strict"
70+
reportUnknownMemberType = false
71+
6972

7073
[tool.ruff.lint]
7174
extend-select = [

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77

88
@pytest.fixture
9-
def poetry_cwd():
9+
def poetry_cwd() -> pathlib.Path:
1010
return pathlib.Path(__file__).parent

tests/test_common.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from __future__ import annotations
22

3+
from pathlib import Path
4+
35
from poetry_to_pre_commit import common
46

57

6-
def test_get_poetry_packages(poetry_cwd):
8+
def test_get_poetry_packages(poetry_cwd: Path) -> None:
79
result = list(
810
common.get_poetry_packages(
911
cwd=poetry_cwd,
@@ -13,7 +15,7 @@ def test_get_poetry_packages(poetry_cwd):
1315
assert common.PoetryPackage(name="attrs", version="23.2.0") in result
1416

1517

16-
def test_pre_commit_config_roundtrip__no_change(tmp_path):
18+
def test_pre_commit_config_roundtrip__no_change(tmp_path: Path) -> None:
1719
file = tmp_path / "file.yaml"
1820
yaml = "a: 1\nb: 2\n"
1921
file.write_text(yaml)
@@ -22,7 +24,7 @@ def test_pre_commit_config_roundtrip__no_change(tmp_path):
2224
assert file.read_text() == yaml
2325

2426

25-
def test_pre_commit_config_roundtrip__write_back(tmp_path):
27+
def test_pre_commit_config_roundtrip__write_back(tmp_path: Path) -> None:
2628
file = tmp_path / "file.yaml"
2729
yaml = "a: 1\nb: 2\n"
2830
file.write_text(yaml)

tests/test_sync_hooks_additional_dependencies.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from pathlib import Path
4+
35
import pytest
46
import ruamel.yaml
57

@@ -13,32 +15,34 @@
1315
("foo=bar,baz", ("foo", {"bar", "baz"})),
1416
],
1517
)
16-
def test_format_bind(value, expected):
18+
def test_format_bind(value: str, expected: tuple[str, set[str]]) -> None:
1719
assert sync_hooks_additional_dependencies.format_bind(value=value) == expected
1820

1921

20-
def test_format_bind__error():
22+
def test_format_bind__error() -> None:
2123
with pytest.raises(ValueError):
2224
sync_hooks_additional_dependencies.format_bind(value="foo")
2325

2426

25-
def test_combine_bind_values():
27+
def test_combine_bind_values() -> None:
2628
bind = [("foo", {"bar"}), ("foo", {"baz"}), ("qux", {"quux"})]
2729
assert sync_hooks_additional_dependencies.combine_bind_values(bind=bind) == {
2830
"foo": {"bar", "baz"},
2931
"qux": {"quux"},
3032
}
3133

3234

33-
def test_get_sync_hooks_additional_dependencies_parser():
34-
parser = sync_hooks_additional_dependencies.get_sync_hooks_additional_dependencies_parser()
35+
def test_get_sync_hooks_additional_dependencies_parser() -> None:
36+
parser = (
37+
sync_hooks_additional_dependencies.get_sync_hooks_additional_dependencies_parser()
38+
)
3539
assert parser.parse_args(["--bind", "foo=bar,baz", "--bind", "foo=qux"]).bind == [
3640
("foo", {"bar", "baz"}),
3741
("foo", {"qux"}),
3842
]
3943

4044

41-
def test_get_poetry_deps(poetry_cwd):
45+
def test_get_poetry_deps(poetry_cwd: Path) -> None:
4246
results = list(
4347
sync_hooks_additional_dependencies.get_poetry_deps(
4448
cwd=poetry_cwd,
@@ -53,7 +57,7 @@ def test_get_poetry_deps(poetry_cwd):
5357
]
5458

5559

56-
def test_get_poetry_deps__error(poetry_cwd):
60+
def test_get_poetry_deps__error(poetry_cwd: Path) -> None:
5761
with pytest.raises(SystemError):
5862
list(
5963
sync_hooks_additional_dependencies.get_poetry_deps(
@@ -63,11 +67,11 @@ def test_get_poetry_deps__error(poetry_cwd):
6367
)
6468

6569

66-
def test__sync_hooks_additional_dependencies():
70+
def test__sync_hooks_additional_dependencies() -> None:
6771
config = {"repos": [{"hooks": [{"id": "mypy"}, {"id": "foo"}]}]}
6872
deps_by_group = {
69-
"types": ["bar==1", "baz[e]==2"],
70-
"main": ["qux==3"],
73+
"types": {"bar==1", "baz[e]==2"},
74+
"main": {"qux==3"},
7175
}
7276
bind = {"mypy": {"types", "main", "unknown"}, "other_unknown": {"abc"}}
7377
sync_hooks_additional_dependencies._sync_hooks_additional_dependencies(
@@ -94,7 +98,7 @@ def test__sync_hooks_additional_dependencies():
9498
}
9599

96100

97-
def test_sync_hooks_additional_dependencies(tmp_path, poetry_cwd):
101+
def test_sync_hooks_additional_dependencies(tmp_path: Path, poetry_cwd: Path) -> None:
98102
pre_commit_path = tmp_path / ".pre-commit-config.yaml"
99103
ruamel.yaml.YAML().dump(
100104
{

tests/test_sync_repos.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from pathlib import Path
4+
35
import pytest
46
import ruamel.yaml
57

@@ -14,7 +16,7 @@
1416
("https://github.com/foo/mirrors-bar", "bar"),
1517
],
1618
)
17-
def test_repo_url_to_pypi_name(input, expected):
19+
def test_repo_url_to_pypi_name(input: str, expected: str) -> None:
1820
assert sync_repos.repo_url_to_pypi_name(input) == expected
1921

2022

@@ -37,13 +39,13 @@ def test_repo_url_to_pypi_name(input, expected):
3739
),
3840
],
3941
)
40-
def test_get_parser(input, expected):
42+
def test_get_parser(input: list[str], expected: dict[str, list[str]]) -> None:
4143
parser = sync_repos.get_sync_repos_parser()
4244
args = parser.parse_args(input)
4345
assert vars(args) == expected
4446

4547

46-
def test_get_pre_commit_repos():
48+
def test_get_pre_commit_repos() -> None:
4749
result = sync_repos.get_pre_commit_repos(
4850
config={
4951
"repos": [
@@ -75,12 +77,17 @@ def test_get_pre_commit_repos():
7577
([bar], ["baz"], {"bar": "baz"}, []),
7678
],
7779
)
78-
def test_extract_pypi_names(repos, skip, map, expected):
80+
def test_extract_pypi_names(
81+
repos: list[sync_repos.PreCommitRepo],
82+
skip: list[str],
83+
map: dict[str, str],
84+
expected: list[tuple[str, sync_repos.PreCommitRepo]],
85+
) -> None:
7986
result = sync_repos.extract_pypi_names(repos=repos, skip=skip, map=map)
8087
assert list(result) == expected
8188

8289

83-
def test_write_precommit_config():
90+
def test_write_precommit_config() -> None:
8491
projects = [
8592
(
8693
sync_repos.PreCommitRepo(
@@ -115,7 +122,7 @@ def test_write_precommit_config():
115122
}
116123

117124

118-
def test_sync_repos(tmp_path, poetry_cwd):
125+
def test_sync_repos(tmp_path: Path, poetry_cwd: Path) -> None:
119126
pre_commit_path = tmp_path / ".pre-commit-config.yaml"
120127
ruamel.yaml.YAML().dump(
121128
{

0 commit comments

Comments
 (0)