From 1daefc364ce729820cdbf2e52b2bb7ce8ab6d9fb Mon Sep 17 00:00:00 2001 From: Hugo Herter Date: Tue, 5 Mar 2024 16:16:28 +0100 Subject: [PATCH] Fix: Mypy configuration was inline Solution: Use a dedicated section of pyproject.toml for the configuration of Mypy. This also adds `check_untyped_defs` to force type checking on all code, annotated or not. --- pyproject.toml | 12 ++++++++++-- src/aleph/vm/models.py | 4 +++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index dfd41ea3e..12595d92a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -107,12 +107,12 @@ python = ["3.9", "3.10", "3.11", "3.12"] detached = true dependencies = [ "black==24.1.1", - "mypy==1.6.0", + "mypy==1.8.0", "ruff==0.1.15", "isort==5.13.2", ] [tool.hatch.envs.lint.scripts] -typing = "mypy --install-types --non-interactive --ignore-missing-imports --explicit-package-bases {args:src/aleph/vm/ tests/ examples/example_fastapi runtimes/aleph-debian-12-python}" +typing = "mypy {args:src/aleph/vm/ tests/ examples/example_fastapi runtimes/aleph-debian-12-python}" style = [ # "ruff {args:.}", "black --check --diff {args:.}", @@ -139,6 +139,14 @@ target-version = ["py39"] line-length = 120 #skip-string-normalization = true +[tool.mypy] +python_version = "3.9" +install_types = true +non_interactive = true +ignore_missing_imports = true +explicit_package_bases = true +check_untyped_defs = true + [tool.ruff] target-version = "py39" line-length = 120 diff --git a/src/aleph/vm/models.py b/src/aleph/vm/models.py index 26b74ea42..b36652cb3 100644 --- a/src/aleph/vm/models.py +++ b/src/aleph/vm/models.py @@ -94,6 +94,7 @@ def is_running(self) -> bool: def is_stopping(self) -> bool: return bool(self.times.stopping_at and not self.times.stopped_at) + @property def is_program(self) -> bool: return isinstance(self.message, ProgramContent) @@ -123,7 +124,8 @@ def uses_payment_stream(self) -> bool: return self.message.payment and self.message.payment.is_stream @property - def has_resources(self): + def has_resources(self) -> bool: + assert self.vm, "The VM attribute has to be set before calling has_resources()" return self.vm.resources_path.exists() if self.hypervisor == HypervisorType.firecracker else True def __init__(