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}" 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/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-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 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: diff --git a/pyproject.toml b/pyproject.toml index 7bd942184..413426ce7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -121,6 +121,7 @@ ignore-words-list = [ [tool.mypy] +warn_unreachable = true files = [ "diracx-api/src/**/*.py", "diracx-cli/src/**/*.py", @@ -144,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.*'