From 58557ddf6ee3039b0c5186b54f83cd4060b94929 Mon Sep 17 00:00:00 2001 From: Matthew Evans Date: Sun, 28 Jan 2024 13:48:14 +0000 Subject: [PATCH] Use recommended pydantic+mypy settings and fix linting --- .pre-commit-config.yaml | 1 + pyproject.toml | 15 +++++++++++++-- src/jobflow_remote/config/settings.py | 2 +- src/jobflow_remote/jobs/data.py | 4 +++- src/jobflow_remote/testing/__init__.py | 1 + 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ca7c6ce7..c409822d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -57,6 +57,7 @@ repos: - tokenize-rt==4.1.0 - types-pkg_resources==0.1.2 - types-paramiko + - pydantic~=2.0 - repo: https://github.com/codespell-project/codespell rev: v2.2.6 hooks: diff --git a/pyproject.toml b/pyproject.toml index f27ffdca..013aafbe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -91,8 +91,19 @@ rst-roles = "class, func, ref, obj" [tool.mypy] ignore_missing_imports = true -no_strict_optional = true -follow_imports = "skip" +strict_optional = false +plugins = "pydantic.mypy" +follow_imports = "ignore" +warn_redundant_casts = true +warn_unused_ignores = true +check_untyped_defs = false +no_implicit_reexport = true +disallow_untyped_defs = false + +[tool.pydantic-mypy] +init_forbid_extra = true +init_typed = true +warn_required_dynamic_aliases = true [tool.pytest.ini_options] filterwarnings = [ diff --git a/src/jobflow_remote/config/settings.py b/src/jobflow_remote/config/settings.py index b322d89d..08334088 100644 --- a/src/jobflow_remote/config/settings.py +++ b/src/jobflow_remote/config/settings.py @@ -35,7 +35,7 @@ class JobflowRemoteSettings(BaseSettings): @model_validator(mode="before") @classmethod - def load_default_settings(cls, values): + def load_default_settings(cls, values: dict) -> dict: """ Load settings from file or environment variables. diff --git a/src/jobflow_remote/jobs/data.py b/src/jobflow_remote/jobs/data.py index 43d81303..fe4f73ce 100644 --- a/src/jobflow_remote/jobs/data.py +++ b/src/jobflow_remote/jobs/data.py @@ -415,7 +415,9 @@ def from_query_dict(cls, d) -> "FlowInfo": parents.append(job_doc["parents"] or []) job_hosts.append(job_doc["job"]["hosts"] or []) else: - db_ids, job_ids, job_indexes = list(zip(*d["ids"])) + db_ids, job_ids, job_indexes = list( # type:ignore[assignment] + zip(*d["ids"]) + ) # parents could be determined in this case as well from the Flow document. # However, to match the correct order it would require lopping over them. # To keep the generation faster add this only if a use case shows up. diff --git a/src/jobflow_remote/testing/__init__.py b/src/jobflow_remote/testing/__init__.py index 8ff03cb7..cf3eec46 100644 --- a/src/jobflow_remote/testing/__init__.py +++ b/src/jobflow_remote/testing/__init__.py @@ -1,4 +1,5 @@ """A series of toy workflows that can be used for testing.""" + from typing import Callable, Optional, Union from jobflow import job