From b3d60be7a70763348b12448b0cbdcdde0619ac06 Mon Sep 17 00:00:00 2001
From: Daniel <d.hornung@indiscale.com>
Date: Tue, 8 Apr 2025 15:14:00 +0200
Subject: [PATCH] REFACTOR: Linting, PEPping, styling, docs.

---
 src/caosadvancedtools/json_schema_exporter.py          |  7 ++++---
 .../table_json_conversion/export_import_xlsx.py        | 10 +++++-----
 .../table_json_conversion/fill_xlsx.py                 |  5 ++++-
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/caosadvancedtools/json_schema_exporter.py b/src/caosadvancedtools/json_schema_exporter.py
index bce3102e..fcccd298 100644
--- a/src/caosadvancedtools/json_schema_exporter.py
+++ b/src/caosadvancedtools/json_schema_exporter.py
@@ -124,8 +124,8 @@ class JsonSchemaExporter:
             that the exporter may fail if this option is activated and the data model is not
             self-sufficient.
         use_rt_pool : models.data_model.DataModel, optional
-            If given, do not attempt to retrieve RecordType information remotely but from this parameter
-            instead.
+            If given, do not attempt to retrieve RecordType information remotely but from this
+            parameter instead.
         multiple_choice : list[str], optional
             A list of reference Property names which shall be denoted as multiple choice properties.
             This means that each option in this property may be selected at most once.  This is not
@@ -341,7 +341,8 @@ ui_schema : dict
                             rt = db.Entity()
 
                     if isinstance(rt, str):
-                        raise NotImplementedError("Behavior is not implemented when _no_remote == True and datatype is given as a string.")
+                        raise NotImplementedError("Behavior is not implemented when _no_remote == "
+                                                  "True and datatype is given as a string.")
 
                     subschema, ui_schema = self._make_segment_from_recordtype(rt)
                     if prop.is_reference():
diff --git a/src/caosadvancedtools/table_json_conversion/export_import_xlsx.py b/src/caosadvancedtools/table_json_conversion/export_import_xlsx.py
index 99097b4a..638b2c32 100644
--- a/src/caosadvancedtools/table_json_conversion/export_import_xlsx.py
+++ b/src/caosadvancedtools/table_json_conversion/export_import_xlsx.py
@@ -25,7 +25,7 @@ import json
 import tempfile
 import warnings
 import logging
-from typing import Union
+from typing import Optional, Union
 from pathlib import Path
 
 import linkahead
@@ -44,7 +44,7 @@ logging.disable(logging.NOTSET)
 
 
 def _generate_jsonschema_from_recordtypes(recordtypes: list,
-                                          out_path: Union[str, Path] = None) -> dict:
+                                          out_path: Optional[Union[str, Path]] = None) -> dict:
     """
     Generate a combined jsonschema for all given recordtypes.
 
@@ -52,7 +52,7 @@ def _generate_jsonschema_from_recordtypes(recordtypes: list,
     ----------
     recordtypes : Iterable
         List of RecordType entities for which a schema should be generated.
-    out_path : str, Path
+    out_path : str or Path, optional
         If given, the resulting jsonschema will also be written to the file
         given by out_path.
         Optional, default None
@@ -78,7 +78,7 @@ def _generate_jsonschema_from_recordtypes(recordtypes: list,
 
 
 def _generate_jsondata_from_records(records: Container,
-                                    out_path: Union[str, Path] = None) -> dict:
+                                    out_path: Optional[Union[str, Path]] = None) -> dict:
     """
     Extract relevant information (id, name, properties, etc.) from the given
     records and converts this information to json.
@@ -87,7 +87,7 @@ def _generate_jsondata_from_records(records: Container,
     ----------
     records :  Iterable
         List of Record entities from which the data will be converted to json.
-    out_path : str, Path
+    out_path : str or Path, optional
         If given, the resulting jsondata will also be written to the file given
         by out_path.
         Optional, default None
diff --git a/src/caosadvancedtools/table_json_conversion/fill_xlsx.py b/src/caosadvancedtools/table_json_conversion/fill_xlsx.py
index e6268fd6..b92adc10 100644
--- a/src/caosadvancedtools/table_json_conversion/fill_xlsx.py
+++ b/src/caosadvancedtools/table_json_conversion/fill_xlsx.py
@@ -331,7 +331,7 @@ to_insert: Optional[dict[str, str]]
 
 
 def fill_template(data: Union[dict, str, TextIO], template: str, result: str,
-                  validation_schema: Union[dict, str, TextIO] = None) -> None:
+                  validation_schema: Optional[Union[dict, str, TextIO]] = None) -> None:
     """Insert json data into an xlsx file, according to a template.
 
 This function fills the json data into the template stored at ``template`` and stores the result as
@@ -355,6 +355,9 @@ validation_schema: dict, optional
 
     # Validation
     if validation_schema is not None:
+        validation_schema = read_or_dict(validation_schema)
+        assert isinstance(validation_schema, dict)
+
         # convert to array_schema if given schema is a model_schema
         if 'properties' in validation_schema and validation_schema['properties'].values():
             if list(validation_schema['properties'].values())[0]["type"] != "array":
-- 
GitLab