From 83cfa47866f39df93a1d82eb8b8b852bd9c3e502 Mon Sep 17 00:00:00 2001 From: martynia Date: Mon, 5 May 2025 14:53:40 +0200 Subject: [PATCH 1/5] feat: add [redundant-expr, truthy-bool] to mypy --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 7bd942184..734c9c6f5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -121,6 +121,8 @@ ignore-words-list = [ [tool.mypy] +warn_unreachable = true +enable_error_code = ["redundant-expr", "truthy-bool"] files = [ "diracx-api/src/**/*.py", "diracx-cli/src/**/*.py", From 14775010dcc9dcbc8e4374077c8b0a631448748e Mon Sep 17 00:00:00 2001 From: martynia Date: Tue, 6 May 2025 13:10:57 +0200 Subject: [PATCH 2/5] fix: duplicates in toml --- pyproject.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 734c9c6f5..413426ce7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -122,7 +122,6 @@ ignore-words-list = [ [tool.mypy] warn_unreachable = true -enable_error_code = ["redundant-expr", "truthy-bool"] files = [ "diracx-api/src/**/*.py", "diracx-cli/src/**/*.py", @@ -146,7 +145,7 @@ allow_redefinition = true explicit_package_bases = true # disallow_untyped_defs = true # strict = true -enable_error_code = ["import", "attr-defined"] +enable_error_code = ["import", "attr-defined", "redundant-expr", "truthy-bool"] [[tool.mypy.overrides]] module = 'DIRAC.*' From 1469c516dda38e6c89ecca7ea1ba84e9224a7e4c Mon Sep 17 00:00:00 2001 From: martynia Date: Tue, 1 Jul 2025 16:21:57 +0200 Subject: [PATCH 3/5] fix: 2 MyPy fixes --- diracx-core/src/diracx/core/preferences.py | 2 +- diracx-core/src/diracx/core/utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/diracx-core/src/diracx/core/preferences.py b/diracx-core/src/diracx/core/preferences.py index d2e0cc111..67bfde6a7 100644 --- a/diracx-core/src/diracx/core/preferences.py +++ b/diracx-core/src/diracx/core/preferences.py @@ -50,7 +50,7 @@ def from_env(cls): @field_validator("log_level", mode="before") @classmethod - def validate_log_level(cls, v: str): + def validate_log_level(cls, v: str | LogLevels): if isinstance(v, str): return getattr(LogLevels, v.upper()) return v diff --git a/diracx-core/src/diracx/core/utils.py b/diracx-core/src/diracx/core/utils.py index ff7309af5..8fcb6c552 100644 --- a/diracx-core/src/diracx/core/utils.py +++ b/diracx-core/src/diracx/core/utils.py @@ -57,7 +57,7 @@ def serialize_credentials(token_response: TokenResponse) -> str: return json.dumps(credential_data) -def read_credentials(location: Path) -> TokenResponse: +def read_credentials(location: Path | None) -> TokenResponse: """Read credentials from a file.""" from diracx.core.preferences import get_diracx_preferences From 039057f668141a6f9e1cfc9bc45962e4d4dda1fb Mon Sep 17 00:00:00 2001 From: martynia Date: Wed, 2 Jul 2025 11:50:55 +0200 Subject: [PATCH 4/5] fix: change _apply_default_scgeme signature to any --- diracx-core/src/diracx/core/config/sources.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diracx-core/src/diracx/core/config/sources.py b/diracx-core/src/diracx/core/config/sources.py index 1cf9cc622..51a6f26f8 100644 --- a/diracx-core/src/diracx/core/config/sources.py +++ b/diracx-core/src/diracx/core/config/sources.py @@ -12,7 +12,7 @@ from datetime import datetime, timezone from pathlib import Path from tempfile import TemporaryDirectory -from typing import Annotated +from typing import Annotated, Any from urllib.parse import urlparse, urlunparse import sh @@ -43,7 +43,7 @@ def is_running_in_async_context(): return False -def _apply_default_scheme(value: str) -> str: +def _apply_default_scheme(value: Any) -> Any: """Applies the default git+file:// scheme if not present.""" if isinstance(value, str) and "://" not in value: value = f"git+file://{value}" From 7a5ecb94787d187bd440df1164a2a96e62dc14a5 Mon Sep 17 00:00:00 2001 From: martynia Date: Wed, 2 Jul 2025 13:18:15 +0200 Subject: [PATCH 5/5] fix address some more MyPy errors --- diracx-core/src/diracx/core/settings.py | 2 +- diracx-logic/src/diracx/logic/jobs/status.py | 2 +- diracx-routers/src/diracx/routers/health/probes.py | 12 +++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/diracx-core/src/diracx/core/settings.py b/diracx-core/src/diracx/core/settings.py index ef11459f8..c9e2c9ec5 100644 --- a/diracx-core/src/diracx/core/settings.py +++ b/diracx-core/src/diracx/core/settings.py @@ -106,7 +106,7 @@ def __init__(self, data: str): self.fernet = Fernet(self.get_secret_value()) -def _apply_default_scheme(value: str) -> str: +def _apply_default_scheme(value: Any) -> Any: """Applies the default file:// scheme if not present.""" if isinstance(value, str) and "://" not in value: value = f"file://{value}" diff --git a/diracx-logic/src/diracx/logic/jobs/status.py b/diracx-logic/src/diracx/logic/jobs/status.py index a5f2b2dc0..82b670137 100644 --- a/diracx-logic/src/diracx/logic/jobs/status.py +++ b/diracx-logic/src/diracx/logic/jobs/status.py @@ -490,7 +490,7 @@ async def remove_jobs_from_task_queue( # TODO: move to Celery # If the task queue is not empty, do not remove it - if not task_queue_db.is_task_queue_empty(tq_id): + if not await task_queue_db.is_task_queue_empty(tq_id): continue await task_queue_db.delete_task_queue(tq_id) diff --git a/diracx-routers/src/diracx/routers/health/probes.py b/diracx-routers/src/diracx/routers/health/probes.py index 1de3f8608..f5701f9f8 100644 --- a/diracx-routers/src/diracx/routers/health/probes.py +++ b/diracx-routers/src/diracx/routers/health/probes.py @@ -20,7 +20,9 @@ async def liveness(config: Config): The method doesn't use the config but we want to depend on it so the check fails if the config expires without managing to refresh. """ - assert config # Depend on the config so we know it's loaded successfully + assert ( + config is not None + ) # Depend on the config so we know it's loaded successfully return JSONResponse(content={"status": "live"}) @@ -31,7 +33,9 @@ async def ready(config: Config, auth_db: AuthDB): Checks if at least the configuration is loaded and the AuthDB database connection is available. """ - assert config # Depend on the config so we know it's loaded successfully + assert ( + config is not None + ) # Depend on the config so we know it's loaded successfully try: await auth_db.ping() except Exception as e: @@ -46,7 +50,9 @@ async def startup(config: Config, auth_db: AuthDB): Checks if at least the configuration is loaded and the AuthDB database connection is available. """ - assert config # Depend on the config so we know it's loaded successfully + assert ( + config is not None + ) # Depend on the config so we know it's loaded successfully try: await auth_db.ping() except Exception as e: