diff --git a/scanpipe/pipes/__init__.py b/scanpipe/pipes/__init__.py index 7fd885c36f..391ea0c2f8 100644 --- a/scanpipe/pipes/__init__.py +++ b/scanpipe/pipes/__init__.py @@ -26,8 +26,10 @@ import sys import time import uuid +from collections.abc import Callable from contextlib import suppress from datetime import datetime +from typing import Any from itertools import islice from pathlib import Path @@ -548,7 +550,7 @@ def get_resource_diff_ratio(resource_a, resource_b): ) -def poll_until_success(check, sleep=10, **kwargs): +def poll_until_success(check: Callable[..., Any], sleep: int = 10, **kwargs: Any) -> bool: """ Given a function `check`, which returns the status of a run, return True when the run instance has completed successfully. @@ -577,7 +579,7 @@ def poll_until_success(check, sleep=10, **kwargs): time.sleep(sleep) -def run_command_safely(command_args): +def run_command_safely(command_args: list[str]) -> str: """ Execute the external commands following security best practices. diff --git a/scanpipe/pipes/vulnerablecode.py b/scanpipe/pipes/vulnerablecode.py index 6c6073b5d0..e67fa7ce6d 100644 --- a/scanpipe/pipes/vulnerablecode.py +++ b/scanpipe/pipes/vulnerablecode.py @@ -118,6 +118,7 @@ def request_post( data, timeout=None, ): + """Wrap the HTTP POST request calls on the API.""" try: response = session.post(url, json=data, timeout=timeout) response.raise_for_status() diff --git a/scanpipe/views.py b/scanpipe/views.py index 9913d4947f..1fe9859f43 100644 --- a/scanpipe/views.py +++ b/scanpipe/views.py @@ -26,6 +26,7 @@ import operator from collections import Counter from contextlib import suppress +from typing import Any from django.apps import apps from django.conf import settings @@ -192,7 +193,7 @@ ] -def purldb_is_configured(*args): +def purldb_is_configured(*args: Any) -> bool: return purldb.is_configured() @@ -203,21 +204,21 @@ def get_queryset(self): return super().get_queryset().prefetch_related(*self.prefetch_related) -def render_as_yaml(value): +def render_as_yaml(value: Any) -> str | None: if value: return saneyaml.dump(value, indent=2) -def render_size(size_in_bytes): +def render_size(size_in_bytes: int | None) -> str | None: if size_in_bytes: return f"{size_in_bytes} ({filesizeformat(size_in_bytes)})" -def fields_have_no_values(fields_data): +def fields_have_no_values(fields_data: dict[str, Any]) -> bool: return not any([field_data.get("value") for field_data in fields_data.values()]) -def do_not_disable(*args, **kwargs): +def do_not_disable(*args: Any, **kwargs: Any) -> bool: return False