add type hints to container dz py code

This commit is contained in:
deeplow 2022-08-22 11:46:27 +01:00
parent f44e6521b6
commit 463ff97b97
No known key found for this signature in database
GPG key ID: 577982871529A52A
2 changed files with 9 additions and 8 deletions

View file

@ -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

View file

@ -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