Skip to content

Commit d38e0f4

Browse files
authored
style(types): enable type checking with ty (#407)
Signed-off-by: Alex Lowe <alex.lowe@canonical.com>
1 parent efe60f6 commit d38e0f4

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

Makefile

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ include common.mk
1313
format: format-ruff format-codespell format-prettier ## Run all automatic formatters
1414

1515
.PHONY: lint
16-
lint: lint-ruff lint-codespell lint-mypy lint-prettier lint-pyright lint-shellcheck lint-docs lint-twine ## Run all linters
16+
lint: lint-ruff lint-ty lint-codespell lint-mypy lint-prettier lint-pyright lint-shellcheck lint-docs lint-twine ## Run all linters
1717

1818
.PHONY: pack
1919
pack: pack-pip ## Build all packages
@@ -43,4 +43,18 @@ endif
4343

4444
# If additional build dependencies need installing in order to build the linting env.
4545
.PHONY: install-lint-build-deps
46-
install-lint-build-deps:
46+
install-lint-build-deps: install-ty
47+
48+
.PHONY: lint-ty
49+
lint-ty: install-ty
50+
ty check
51+
52+
.PHONY: install-ty
53+
install-ty:
54+
ifneq ($(shell which ty),)
55+
else ifneq ($(shell which snap),)
56+
sudo snap install --beta astral-ty
57+
sudo snap alias astral-ty.ty ty
58+
else ifneq ($(shell which uv),)
59+
uv tool install ty
60+
endif

craft_cli/pytest_plugin.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ def assert_interactions(self, expected_call_list: list[_Call] | None) -> None:
208208
"""
209209
if expected_call_list is None:
210210
if self.interactions:
211-
show_interactions = "\n".join(map(str, self.interactions))
211+
show_interactions = "\n".join(
212+
str(interaction) for interaction in self.interactions
213+
)
212214
raise AssertionError(
213215
"Expected no call but really got:\n" + show_interactions
214216
)

examples.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,8 @@ def example_35() -> None:
606606
if func is None:
607607
print(f"ERROR: function {name!r} not found")
608608
sys.exit()
609+
# https://github.com/astral-sh/ty/issues/690
610+
assert func is not None # noqa: S101, type narrowing
609611

610612
if int(sys.argv[1]) != 29: # noqa: PLR2004, magic value
611613
emit.init(EmitterMode.BRIEF, "examples", "Greetings earthlings")

0 commit comments

Comments
 (0)