From 0a24495149ebfffe380861fa57f5bba4b756535f Mon Sep 17 00:00:00 2001 From: Daniel <d.hornung@indiscale.com> Date: Tue, 4 Jun 2024 12:40:32 +0200 Subject: [PATCH] MAINT: Explicit optional. --- src/caoscrawler/conv_impl/spss.py | 3 ++- src/caoscrawler/crawl.py | 2 +- src/caoscrawler/hdf5_converter.py | 6 ++++-- src/caoscrawler/identifiable.py | 9 +++++---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/caoscrawler/conv_impl/spss.py b/src/caoscrawler/conv_impl/spss.py index 2b11ebe0..824d4f8e 100644 --- a/src/caoscrawler/conv_impl/spss.py +++ b/src/caoscrawler/conv_impl/spss.py @@ -28,6 +28,7 @@ import yaml from .. import converters from ..stores import GeneralStore from ..structure_elements import (File, StructureElement) +from typing import Optional TYPES = { @@ -56,7 +57,7 @@ class SPSSConverter(converters.TableConverter): return self._children_from_dataframe(df) -def spss_to_yaml(savfile: str, yamlfile: str, cfood: str = None) -> None: +def spss_to_yaml(savfile: str, yamlfile: str, cfood: Optional[str] = None) -> None: """Parse the *.sav and create basic datamodel in ``yamlfile``. Parameters diff --git a/src/caoscrawler/crawl.py b/src/caoscrawler/crawl.py index 53172dd2..6fc90e30 100644 --- a/src/caoscrawler/crawl.py +++ b/src/caoscrawler/crawl.py @@ -1307,7 +1307,7 @@ ____________________\n""".format(i + 1, len(pending_changes)) + str(el[3])) res[converter.name]["subtree"][k[0]] = d[k[0]] return res - def save_debug_data(self, filename: str, debug_tree: DebugTree = None): + def save_debug_data(self, filename: str, debug_tree: Optional[DebugTree] = None): """ Save the information contained in a debug_tree to a file named filename. """ diff --git a/src/caoscrawler/hdf5_converter.py b/src/caoscrawler/hdf5_converter.py index 5b1ff577..482d59c1 100644 --- a/src/caoscrawler/hdf5_converter.py +++ b/src/caoscrawler/hdf5_converter.py @@ -18,6 +18,8 @@ # along with this program. If not, see <https://www.gnu.org/licenses/>. # +from typing import Optional + try: import h5py except ModuleNotFoundError: @@ -94,8 +96,8 @@ def convert_h5_element(elt: Union[h5py.Group, h5py.Dataset], name: str): raise ValueError("The given element must be either a HDF5 Group or Dataset object.") -def convert_basic_element_with_nd_array(value, name: str = None, - internal_path: str = None, msg_prefix: str = ""): +def convert_basic_element_with_nd_array(value, name: Optional[str] = None, + internal_path: Optional[str] = None, msg_prefix: str = ""): """Convert a given object either to an ndarray structure element or to a basic scalar structure element. diff --git a/src/caoscrawler/identifiable.py b/src/caoscrawler/identifiable.py index cefdf4a0..e69e1092 100644 --- a/src/caoscrawler/identifiable.py +++ b/src/caoscrawler/identifiable.py @@ -24,7 +24,7 @@ import linkahead as db from datetime import datetime import json from hashlib import sha256 -from typing import Union +from typing import Optional, Union import logging logger = logging.getLogger(__name__) @@ -50,9 +50,10 @@ class Identifiable(): backrefs: list, TODO future """ - def __init__(self, record_id: int = None, path: str = None, record_type: str = None, - name: str = None, properties: dict = None, - backrefs: list[Union[int, str]] = None): + def __init__(self, record_id: Optional[int] = None, path: Optional[str] = None, + record_type: Optional[str] = None, + name: Optional[str] = None, properties: Optional[dict] = None, + backrefs: Optional[list[Union[int, str]]] = None): if (record_id is None and path is None and name is None and (backrefs is None or len(backrefs) == 0) and (properties is None or len(properties) == 0)): -- GitLab