Skip to content

Commit 0669603

Browse files
committed
Add type hints and missing docstring for code quality improvements
1 parent 75d6c9e commit 0669603

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

scanpipe/pipes/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
import sys
2727
import time
2828
import uuid
29+
from collections.abc import Callable
2930
from contextlib import suppress
3031
from datetime import datetime
32+
from typing import Any
3133
from itertools import islice
3234
from pathlib import Path
3335

@@ -548,7 +550,7 @@ def get_resource_diff_ratio(resource_a, resource_b):
548550
)
549551

550552

551-
def poll_until_success(check, sleep=10, **kwargs):
553+
def poll_until_success(check: Callable[..., Any], sleep: int = 10, **kwargs: Any) -> bool:
552554
"""
553555
Given a function `check`, which returns the status of a run, return True
554556
when the run instance has completed successfully.
@@ -577,7 +579,7 @@ def poll_until_success(check, sleep=10, **kwargs):
577579
time.sleep(sleep)
578580

579581

580-
def run_command_safely(command_args):
582+
def run_command_safely(command_args: list[str]) -> str:
581583
"""
582584
Execute the external commands following security best practices.
583585

scanpipe/pipes/vulnerablecode.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def request_post(
118118
data,
119119
timeout=None,
120120
):
121+
"""Wrap the HTTP POST request calls on the API."""
121122
try:
122123
response = session.post(url, json=data, timeout=timeout)
123124
response.raise_for_status()

scanpipe/views.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import operator
2727
from collections import Counter
2828
from contextlib import suppress
29+
from typing import Any
2930

3031
from django.apps import apps
3132
from django.conf import settings
@@ -192,7 +193,7 @@
192193
]
193194

194195

195-
def purldb_is_configured(*args):
196+
def purldb_is_configured(*args: Any) -> bool:
196197
return purldb.is_configured()
197198

198199

@@ -203,21 +204,21 @@ def get_queryset(self):
203204
return super().get_queryset().prefetch_related(*self.prefetch_related)
204205

205206

206-
def render_as_yaml(value):
207+
def render_as_yaml(value: Any) -> str | None:
207208
if value:
208209
return saneyaml.dump(value, indent=2)
209210

210211

211-
def render_size(size_in_bytes):
212+
def render_size(size_in_bytes: int | None) -> str | None:
212213
if size_in_bytes:
213214
return f"{size_in_bytes} ({filesizeformat(size_in_bytes)})"
214215

215216

216-
def fields_have_no_values(fields_data):
217+
def fields_have_no_values(fields_data: dict[str, Any]) -> bool:
217218
return not any([field_data.get("value") for field_data in fields_data.values()])
218219

219220

220-
def do_not_disable(*args, **kwargs):
221+
def do_not_disable(*args: Any, **kwargs: Any) -> bool:
221222
return False
222223

223224

0 commit comments

Comments
 (0)