From f583ce09cfd228850b4f8f1e37dd91ffb5fc594c Mon Sep 17 00:00:00 2001 From: Romin Benfer <romin.benfer@rwth-aachen.de> Date: Thu, 10 Nov 2022 22:51:07 +0100 Subject: [PATCH] Fix: PEP 484 prohibits implicit Optional (mypy-0.990) --- src/coscine/client.py | 6 +++--- src/coscine/form.py | 1 + src/coscine/object.py | 11 +++++++---- src/coscine/project.py | 2 +- src/coscine/resource.py | 8 ++++---- src/coscine/utils.py | 2 +- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/coscine/client.py b/src/coscine/client.py index 2c4d02a..b70dd7c 100644 --- a/src/coscine/client.py +++ b/src/coscine/client.py @@ -28,7 +28,7 @@ with Coscine servers. ############################################################################### from __future__ import annotations -from typing import List, Union +from typing import List, Optional, Union import urllib.parse import json import logging @@ -502,7 +502,7 @@ class Client: ############################################################################### - def project_form(self, data: dict = None) -> ProjectForm: + def project_form(self, data: Optional[dict] = None) -> ProjectForm: """ Returns an empty project form. @@ -519,7 +519,7 @@ class Client: ############################################################################### - def resource_form(self, data: dict = None) -> ResourceForm: + def resource_form(self, data: Optional[dict] = None) -> ResourceForm: """ Returns an empty resource form. diff --git a/src/coscine/form.py b/src/coscine/form.py index bdb9197..34e1cb5 100644 --- a/src/coscine/form.py +++ b/src/coscine/form.py @@ -649,6 +649,7 @@ class InputForm: """ Generates Coscine formatted json-ld from an InputForm. """ + return {} ############################################################################### diff --git a/src/coscine/object.py b/src/coscine/object.py index 5bdd2e9..43ea609 100644 --- a/src/coscine/object.py +++ b/src/coscine/object.py @@ -240,7 +240,7 @@ class FileObject: ############################################################################### def __init__(self, resource: Resource, data: dict, - metadata: dict = None) -> None: + metadata: Optional[dict] = None) -> None: """ Initializes the Coscine FileObject. @@ -366,9 +366,12 @@ class FileObject: ############################################################################### - def download(self, path: str = "./", - callback: Callable[[int], None] = None, - preserve_path: bool = False) -> None: + def download( + self, + path: str = "./", + callback: Optional[Callable[[int], None]] = None, + preserve_path: Optional[bool] = False + ) -> None: """ Downloads the file-like object to the local harddrive. diff --git a/src/coscine/project.py b/src/coscine/project.py index a7a5e51..19fe07c 100644 --- a/src/coscine/project.py +++ b/src/coscine/project.py @@ -139,7 +139,7 @@ class Project: ############################################################################### def __init__(self, client: Client, data: dict, - parent: Project = None) -> None: + parent: Optional[Project] = None) -> None: """ Initializes a Coscine project object. diff --git a/src/coscine/resource.py b/src/coscine/resource.py index 9129650..d3103ae 100644 --- a/src/coscine/resource.py +++ b/src/coscine/resource.py @@ -397,7 +397,7 @@ class Resource: ############################################################################### - def objects(self, path: str = None) -> List[FileObject]: + def objects(self, path: Optional[str] = None) -> List[FileObject]: """ Returns a list of Objects stored within the resource. @@ -485,7 +485,7 @@ class Resource: key: str, file, metadata: Union[MetadataForm, dict], - callback: Callable[[int], None] = None + callback: Optional[Callable[[int], None]] = None ) -> None: """ Uploads a file-like object to a resource on the Coscine server @@ -535,7 +535,7 @@ class Resource: self, key: str, file_handle, - callback: Callable[[int], None] = None + callback: Optional[Callable[[int], None]] = None ) -> None: uri = self.client.uri("Blob", "Blob", self.id) fields = {"files": (key, file_handle, "application/octect-stream")} @@ -620,7 +620,7 @@ class Resource: ############################################################################### - def metadata_form(self, data: dict = None) -> MetadataForm: + def metadata_form(self, data: Optional[dict] = None) -> MetadataForm: """ Creates a MetadataForm for this resource diff --git a/src/coscine/utils.py b/src/coscine/utils.py index 20fc8ea..ab99716 100644 --- a/src/coscine/utils.py +++ b/src/coscine/utils.py @@ -150,7 +150,7 @@ class ProgressBar: ############################################################################### def __init__(self, enabled: bool, filesize: int, key: str, - callback: Callable[[int], None] = None) -> None: + callback: Optional[Callable[[int], None]] = None) -> None: """ Initializes a state-aware tqdm ProgressBar. -- GitLab