Skip to content

Commit 16e413b

Browse files
committed
Add ty type checker
Add ty configuration. ty provides fast type checking that complements pyright/mypy, while ruff handles missing type hints detection. ty is not yet reporting as much problems as mypy or pyright, but it is much, much faster, and is already interesting to use interactively. This change only aims at making ty usable in this project, without replacing mypy or pyright. As such it is not added in the dev dependencies and must be installed manually, for example with uv tool install ty Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
1 parent 8a44f16 commit 16e413b

7 files changed

Lines changed: 41 additions & 25 deletions

File tree

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ repos:
3333
require_serial: true
3434
entry: "uv run flake8"
3535
types: ["python"]
36+
- id: "ty"
37+
name: "ty"
38+
language: "system"
39+
require_serial: true
40+
entry: "uv run ty check ."
41+
types: ["python"]
42+
stages: ["manual"]
43+
pass_filenames: false
44+
always_run: true
3645
- id: "mypy"
3746
name: "mypy"
3847
language: "system"

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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 ruff-fix flake8 autopep8 autopep8-fix
4+
.PHONY: all mypy pyright ruff ruff-fix flake8 autopep8 autopep8-fix ty
55

66
# By default, only run the non-fix version of the hooks so it doesn't modify any files
77
# It runs on all files managed by git (untracked files are not checked)
@@ -19,5 +19,5 @@ vm_data.py:
1919

2020
mypy pyright ruff: data.py vm_data.py
2121

22-
ruff ruff-fix autopep8 autopep8-fix flake8 mypy pyright:
22+
ruff ruff-fix autopep8 autopep8-fix flake8 ty mypy pyright:
2323
uv run prek -a $@

conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ def pytest_runtest_makereport(
280280

281281
# store test results for each phase of a call, which can
282282
# be "setup", "call", "teardown"
283+
assert rep.when is not None
283284
item.stash.setdefault(PHASE_REPORT_KEY, {})[rep.when] = rep
284285

285286
return rep

data.py-dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ ISO_IMAGES: dict[str, "IsoImageDef"] = {
171171
# - 'default': keep using the pool's default SR
172172
# - 'local': use the first local SR found instead
173173
# - A UUID of the SR to be used
174-
DEFAULT_SR = 'default'
174+
DEFAULT_SR: str = 'default'
175175

176176
# Whether to cache VMs on the test host, that is import them only if not already
177177
# present in the target SR. This also causes the VM to be cloned at the beginning
@@ -182,7 +182,7 @@ DEFAULT_SR = 'default'
182182
# Example description: "[Cache for http://example.com/images/filename.xva]"
183183
# Delete the VM to remove it from cache.
184184
# This setting affects VMs managed by the `imported_vm` fixture.
185-
CACHE_IMPORTED_VM = False
185+
CACHE_IMPORTED_VM: bool = False
186186

187187
# Default LINSTOR redundancy configuration for creating SRs.
188188
LINSTOR_REDUNDANCY = 2

lib/config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
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
7-
write_volume_align = 1
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
7+
write_volume_align: int = 1
88

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

pyproject.toml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@ dependencies = [
2121

2222
[dependency-groups]
2323
dev = [
24+
"autopep8",
2425
"bs4>=0.0.1",
25-
"mypy",
2626
"flake8",
2727
"flake8-pyproject",
28+
"libarchive-c==5.3",
29+
"mypy",
30+
"prek",
2831
"pydocstyle",
2932
"pyright",
3033
"ruff",
31-
"types-requests",
32-
"typing-extensions",
33-
"libarchive-c==5.3",
34-
"types-pygments",
3534
"types-colorama",
35+
"types-passlib",
3636
"types-pexpect",
37+
"types-pygments",
38+
"types-requests",
39+
"typing-extensions",
3740
"zizmor",
38-
"prek",
39-
"autopep8",
40-
"types-passlib",
4141
]
4242

4343
[tool.mypy]
@@ -55,6 +55,9 @@ typeCheckingMode = "standard"
5555
reportMissingParameterType = "error"
5656
reportUnknownParameterType = "error"
5757

58+
[tool.ty.rules]
59+
unused-type-ignore-comment = "ignore"
60+
5861
[tool.ruff]
5962
preview = true
6063
line-length = 120
@@ -65,6 +68,7 @@ quote-style = "preserve"
6568

6669
[tool.ruff.lint]
6770
select = [
71+
"ANN", # flake8-annotations
6872
"D", # pydocstyle
6973
"FA", # future-annotations
7074
"F", # Pyflakes
@@ -78,6 +82,7 @@ select = [
7882
]
7983
# don't use some of the default D and SIM rules
8084
ignore = [
85+
"ANN401", # missing-return-type-special-method. Might be removed later.
8186
"D100", # undocumented-public-module
8287
"D101", # undocumented-public-class
8388
"D102", # undocumented-public-method
@@ -98,6 +103,7 @@ ignore = [
98103
"SIM105", # suppressible-exception
99104
"SIM108", # if-else-block-instead-of-if-exp
100105
]
106+
flake8-annotations.mypy-init-return = true
101107

102108
# restrict to the PEP 257 rules
103109
pydocstyle.convention = "pep257"

requirements/dev.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# generated with update_requirements.py, do not edit manually
2+
autopep8
23
bs4>=0.0.1
3-
mypy
44
flake8
55
flake8-pyproject
6+
libarchive-c==5.3
7+
mypy
8+
prek
69
pydocstyle
710
pyright
811
ruff
9-
types-requests
10-
typing-extensions
11-
libarchive-c==5.3
12-
types-pygments
1312
types-colorama
13+
types-passlib
1414
types-pexpect
15+
types-pygments
16+
types-requests
17+
typing-extensions
1518
zizmor
16-
prek
17-
autopep8
18-
types-passlib
1919
-r base.txt

0 commit comments

Comments
 (0)