From 463ff97b9718990741d6546f31353f96dd4aed40 Mon Sep 17 00:00:00 2001 From: deeplow Date: Mon, 22 Aug 2022 11:46:27 +0100 Subject: [PATCH] add type hints to container dz py code --- Makefile | 2 +- container/dangerzone.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 546af9b..f6ad8cc 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ mypy-container: mypy-dev-scripts: mypy $(MYPY_ARGS) install dev_scripts/* *.py -mypy: mypy-host # mypy-container mypy-dev-scripts ## check type hints with mypy +mypy: mypy-host mypy-container # mypy-dev-scripts ## check type hints with mypy .PHONY: lint lint: lint-black lint-isort mypy ## check the code with various linters diff --git a/container/dangerzone.py b/container/dangerzone.py index 41656fb..1168fe9 100644 --- a/container/dangerzone.py +++ b/container/dangerzone.py @@ -18,19 +18,20 @@ import os import shutil import subprocess import sys +from typing import Dict, Optional import magic from PIL import Image class DangerzoneConverter: - def __init__(self): + def __init__(self) -> None: pass - def document_to_pixels(self): + def document_to_pixels(self) -> int: percentage = 0.0 - conversions = { + conversions: Dict[str, Dict[str, Optional[str]]] = { # .pdf "application/pdf": {"type": None}, # .docx @@ -312,8 +313,8 @@ class DangerzoneConverter: return 0 - def pixels_to_pdf(self): - percentage = 50.0 + def pixels_to_pdf(self) -> int: + percentage: float = 50.0 num_pages = len(glob.glob("/dangerzone/page-*.rgb")) @@ -516,12 +517,12 @@ class DangerzoneConverter: return 0 - def output(self, error, text, percentage): + def output(self, error: bool, text: str, percentage: float) -> None: print(json.dumps({"error": error, "text": text, "percentage": int(percentage)})) sys.stdout.flush() -def main(): +def main() -> int: if len(sys.argv) != 2: print(f"Usage: {sys.argv[0]} [document-to-pixels]|[pixels-to-pdf]") return -1