From 4c077c01db19e8adc01d9559677ad5693a1db909 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 9 Feb 2024 04:22:51 +0300 Subject: Raise error if file is missing rather than returning a Union value. --- qc_app/files.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'qc_app/files.py') diff --git a/qc_app/files.py b/qc_app/files.py index baac5ec..b163612 100644 --- a/qc_app/files.py +++ b/qc_app/files.py @@ -1,17 +1,15 @@ """Utilities to deal with uploaded files.""" import hashlib from pathlib import Path -from typing import Union from datetime import datetime from flask import current_app from werkzeug.utils import secure_filename from werkzeug.datastructures import FileStorage -def save_file(fileobj: FileStorage, upload_dir: Path) -> Union[Path, bool]: +def save_file(fileobj: FileStorage, upload_dir: Path) -> Path: """Save the uploaded file and return the path.""" - if not bool(fileobj): - return False + assert bool(fileobj), "Invalid file object!" hashed_name = hashlib.sha512( f"{fileobj.filename}::{datetime.now().isoformat()}".encode("utf8") ).hexdigest() -- cgit v1.2.3