Skip to content

Commit 2ceb6ba

Browse files
committed
chore: add ty type checker and reorder make commands for faster feedback
Add ty as a development dependency for use as a language server in text editors. ty provides fast type checking that complements pyright/mypy, while ruff handles missing type hints detection. Reorder make commands to run the fastest checks first (ruff, flake8, ty) before the slower mypy and pyright, improving feedback speed. Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
1 parent 782b014 commit 2ceb6ba

10 files changed

Lines changed: 79 additions & 21 deletions

File tree

.github/workflows/code-checkers.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ jobs:
3131
run: cp vm_data.py-dist vm_data.py
3232
- run: pyright .
3333

34+
ty:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
38+
with:
39+
persist-credentials: false
40+
- uses: ./.github/actions/uv-setup/
41+
- name: Create a dummy data.py
42+
run: cp data.py-dist data.py
43+
- name: Create a dummy vm_data.py
44+
run: cp vm_data.py-dist vm_data.py
45+
- run: ty check .
46+
3447
ruff:
3548
runs-on: ubuntu-latest
3649
env:

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ repos:
1313
require_serial: true
1414
entry: "uv run flake8"
1515
types: ["python"]
16+
- id: "ty"
17+
name: "ty"
18+
language: "system"
19+
require_serial: true
20+
entry: "uv run ty check ."
21+
types: ["python"]
1622
- id: "mypy"
1723
name: "mypy"
1824
language: "system"

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Makefile to run static code checkers locally
22
# Equivalent to the GitHub Actions workflow in .github/workflows/code-checkers.yml
33

4-
.PHONY: all mypy pyright ruff flake8
4+
.PHONY: all mypy pyright ruff flake8 ty
55

6-
all: mypy pyright ruff flake8
6+
all: ruff flake8 ty pyright mypy
77

88
data.py:
99
@test -r data.py || echo "File 'data.py' does not exist. Refer to https://github.com/xcp-ng/xcp-ng-tests#configuration." && exit 1
@@ -19,3 +19,6 @@ ruff: data.py
1919

2020
flake8:
2121
uv run flake8
22+
23+
ty: data.py
24+
uv run ty check .

conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ def pytest_runtest_makereport(
186186

187187
# store test results for each phase of a call, which can
188188
# be "setup", "call", "teardown"
189-
item.stash.setdefault(PHASE_REPORT_KEY, {})[rep.when] = rep
189+
assert rep.when is not None
190+
item.stash.setdefault(PHASE_REPORT_KEY, {})[rep.when]# = rep
190191

191192
return rep
192193

lib/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from lib.common import GiB
22

3-
ignore_ssh_banner = False
4-
ssh_output_max_lines = 20
5-
volume_size = 1 * GiB
6-
write_volume_cap = 2 * GiB
3+
ignore_ssh_banner: bool = False
4+
ssh_output_max_lines: int = 20
5+
volume_size: int = 1 * GiB
6+
write_volume_cap: int = 2 * GiB
77

88
def sr_device_config(datakey: str, *, required: list[str] = []) -> dict[str, str]:
99
import data # import here to avoid depending on this user file for collecting tests

lib/host.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ def rescan_block_devices_info(self) -> None:
680680
) # limit to: sd, blkext
681681

682682
self.block_devices_info = [
683-
Host.BlockDeviceInfo({key.lower(): value.strip('"') # type: ignore[misc]
683+
Host.BlockDeviceInfo({key.lower(): value.strip('"') # type: ignore
684684
for key, value in re.findall(r'(\S+)=(".*?"|\S+)', line)})
685685
for line in output_string.strip().splitlines()
686686
]

pyproject.toml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@ dependencies = [
1919
[dependency-groups]
2020
dev = [
2121
"bs4>=0.0.1",
22-
"mypy",
2322
"flake8",
2423
"flake8-pyproject",
24+
"libarchive-c==5.3",
25+
"mypy",
2526
"pydocstyle",
2627
"pyright",
2728
"ruff",
28-
"types-requests",
29-
"typing-extensions",
30-
"libarchive-c==5.3",
31-
"types-pygments",
29+
"ty",
3230
"types-colorama",
3331
"types-pexpect",
32+
"types-pygments",
33+
"types-requests",
34+
"typing-extensions",
3435
"zizmor",
3536
"prek>=0.3.11",
3637
]
@@ -40,6 +41,9 @@ typeCheckingMode = "standard"
4041
reportMissingParameterType = "error"
4142
reportUnknownParameterType = "error"
4243

44+
[tool.ty.rules]
45+
unused-type-ignore-comment = "ignore"
46+
4347
[tool.ruff]
4448
preview = true
4549
line-length = 120
@@ -50,6 +54,7 @@ quote-style = "preserve"
5054

5155
[tool.ruff.lint]
5256
select = [
57+
"ANN", # flake8-annotations
5358
"D", # pydocstyle
5459
"FA", # future-annotations
5560
"F", # Pyflakes
@@ -62,6 +67,7 @@ select = [
6267
]
6368
# don't use some of the default D and SIM rules
6469
ignore = [
70+
"ANN401", # missing-return-type-special-method. Might be removed later.
6571
"D100", # undocumented-public-module
6672
"D101", # undocumented-public-class
6773
"D102", # undocumented-public-method
@@ -82,6 +88,7 @@ ignore = [
8288
"SIM105", # suppressible-exception
8389
"SIM108", # if-else-block-instead-of-if-exp
8490
]
91+
flake8-annotations.mypy-init-return = true
8592

8693
# restrict to the PEP 257 rules
8794
pydocstyle.convention = "pep257"

requirements/dev.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# generated with update_requirements.py, do not edit manually
22
bs4>=0.0.1
3-
mypy
43
flake8
54
flake8-pyproject
5+
libarchive-c==5.3
6+
mypy
67
pydocstyle
78
pyright
89
ruff
9-
types-requests
10-
typing-extensions
11-
libarchive-c==5.3
12-
types-pygments
10+
ty
1311
types-colorama
1412
types-pexpect
13+
types-pygments
14+
types-requests
15+
typing-extensions
1516
zizmor
1617
prek>=0.3.11
1718
-r base.txt

scripts/xva_bridge.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ def __init__(self, member: minidom.Element):
1919

2020
def get_name(self) -> str | None:
2121
for child in self.member.childNodes:
22-
if child.nodeType == minidom.Node.ELEMENT_NODE and child.tagName == "name" and child.firstChild:
22+
if isinstance(child, minidom.Element) and child.tagName == "name" and child.firstChild:
2323
return child.firstChild.nodeValue
2424
return None
2525

2626
def get_value(self) -> str | None:
2727
for child in self.member.childNodes:
28-
if child.nodeType == minidom.Node.ELEMENT_NODE and child.tagName == "value" and child.firstChild:
28+
if isinstance(child, minidom.Element) and child.tagName == "value" and child.firstChild:
2929
return child.firstChild.nodeValue
3030
return None
3131

3232
def set_value(self, value: str) -> None:
3333
for child in self.member.childNodes:
34-
if child.nodeType == minidom.Node.ELEMENT_NODE and child.tagName == "value" and child.firstChild:
34+
if isinstance(child, minidom.Element) and child.tagName == "value" and child.firstChild:
3535
child.firstChild.nodeValue = value # type: ignore
3636
return None
3737

uv.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)