Skip to content

feat: add [redundant-expr, truthy-bool] to mypy #514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions diracx-core/src/diracx/core/config/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion diracx-core/src/diracx/core/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion diracx-core/src/diracx/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion diracx-core/src/diracx/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion diracx-logic/src/diracx/logic/jobs/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@
# 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):

Check warning on line 493 in diracx-logic/src/diracx/logic/jobs/status.py

View check run for this annotation

Codecov / codecov/patch

diracx-logic/src/diracx/logic/jobs/status.py#L493

Added line #L493 was not covered by tests
continue

await task_queue_db.delete_task_queue(tq_id)
Expand Down
12 changes: 9 additions & 3 deletions diracx-routers/src/diracx/routers/health/probes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"})


Expand All @@ -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:
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ ignore-words-list = [


[tool.mypy]
warn_unreachable = true
files = [
"diracx-api/src/**/*.py",
"diracx-cli/src/**/*.py",
Expand All @@ -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.*'
Expand Down
Loading