From 40961b1dd1fa61772dee63858f68983dfe09f9d8 Mon Sep 17 00:00:00 2001
From: "i.nueske" <i.nueske@indiscale.com>
Date: Fri, 13 Dec 2024 12:01:10 +0100
Subject: [PATCH] MNT: Fix various pylint errors:

- Remove unnecessary pass, init without effect, unused variables
- Update use of deprecated methods
- Fix used exception not matching documentation
- Ignore logging-fstring-interpolation, variant of logging-format-interpolation
---
 pylintrc                                      | 1 +
 src/caosadvancedtools/cache.py                | 6 ------
 src/caosadvancedtools/cfood.py                | 1 -
 src/caosadvancedtools/crawler.py              | 4 ++--
 src/caosadvancedtools/import_from_xml.py      | 2 +-
 src/caosadvancedtools/loadFiles.py            | 2 +-
 src/caosadvancedtools/models/parser.py        | 2 +-
 src/caosadvancedtools/scifolder/withreadme.py | 4 ++--
 src/caosadvancedtools/table_converter.py      | 2 +-
 src/caosadvancedtools/utils.py                | 1 -
 src/caosadvancedtools/webui_formatter.py      | 2 +-
 11 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/pylintrc b/pylintrc
index 1be7cd8d..e95afc90 100644
--- a/pylintrc
+++ b/pylintrc
@@ -19,4 +19,5 @@ init-hook=
 disable=
   fixme,
   logging-format-interpolation,
+  logging-fstring-interpolation,
   logging-not-lazy,
diff --git a/src/caosadvancedtools/cache.py b/src/caosadvancedtools/cache.py
index 46564393..5fc1ec3c 100644
--- a/src/caosadvancedtools/cache.py
+++ b/src/caosadvancedtools/cache.py
@@ -94,7 +94,6 @@ class AbstractCache(ABC):
 
         Increase this variable, when changes to the cache tables are made.
         """
-        pass
 
     @abstractmethod
     def create_cache(self):
@@ -102,14 +101,12 @@ class AbstractCache(ABC):
         Provide an overloaded function here that creates the cache in
         the most recent version.
         """
-        pass
 
     @abstractmethod
     def get_default_file_name(self):
         """
         Supply a default file name for the cache here.
         """
-        pass
 
     def check_cache(self):
         """
@@ -192,9 +189,6 @@ class IdentifiableCache(AbstractCache):
     def get_default_file_name(self):
         return "caosdb_identifiable_cache.db"
 
-    def __init__(self, db_file=None, force_creation=False):
-        super().__init__(db_file, force_creation)
-
     def create_cache(self):
         """
         Create a new SQLITE cache file in self.db_file.
diff --git a/src/caosadvancedtools/cfood.py b/src/caosadvancedtools/cfood.py
index 8ae01632..4647a576 100644
--- a/src/caosadvancedtools/cfood.py
+++ b/src/caosadvancedtools/cfood.py
@@ -208,7 +208,6 @@ class AbstractCFood(object, metaclass=ABCMeta):
 
         To be overwritten by subclasses
         """
-        pass
 
     def attach(self, item):
         self.attached_items.append(item)
diff --git a/src/caosadvancedtools/crawler.py b/src/caosadvancedtools/crawler.py
index 9b960d57..dfc5351c 100644
--- a/src/caosadvancedtools/crawler.py
+++ b/src/caosadvancedtools/crawler.py
@@ -487,8 +487,8 @@ ____________________\n""".format(i+1, len(pending_changes)) + str(el[3]))
             logger.error(err_msg)
             logger.error('Crawler finished with Datamodel Errors')
         elif errors_occured:
-            msg = "There were fatal errors during execution, please "
-            "contact the system administrator!"
+            msg = ("There were fatal errors during execution, please contact "
+                   "the system administrator!")
 
             if self.debug_file:
                 msg += "\nPlease provide the following path:\n{}".format(
diff --git a/src/caosadvancedtools/import_from_xml.py b/src/caosadvancedtools/import_from_xml.py
index 4f9bba99..540091b0 100755
--- a/src/caosadvancedtools/import_from_xml.py
+++ b/src/caosadvancedtools/import_from_xml.py
@@ -94,7 +94,7 @@ def import_xml(filename, rerun=False, interactive=True):
 
     if not rerun:
         for _, el in enumerate(files.values()):
-            r = el.insert(unique=False)
+            el.insert(unique=False)
     else:
         for _, el in enumerate(files.values()):
             el.id = None
diff --git a/src/caosadvancedtools/loadFiles.py b/src/caosadvancedtools/loadFiles.py
index 8e3b466f..56d50e4d 100755
--- a/src/caosadvancedtools/loadFiles.py
+++ b/src/caosadvancedtools/loadFiles.py
@@ -122,7 +122,7 @@ def compile_file_list(caosdbignore: str, localpath: str) -> list[str]:
     current_ignore = caosdbignore
     non_ignored_files = []
     ignore_files: list[tuple[str, str]] = []
-    for root, dirs, files in os.walk(localpath):
+    for root, _, files in os.walk(localpath):
         # remove local ignore files that do no longer apply to the current subtree (branch switch)
         while len(ignore_files) > 0 and not root.startswith(ignore_files[-1][0]):
             os.remove(ignore_files[-1][1])
diff --git a/src/caosadvancedtools/models/parser.py b/src/caosadvancedtools/models/parser.py
index f6e142db..1cd1fe6e 100644
--- a/src/caosadvancedtools/models/parser.py
+++ b/src/caosadvancedtools/models/parser.py
@@ -633,7 +633,7 @@ debug : bool, optional
 
         """
 
-        for key, value in self.model.items():
+        for _, value in self.model.items():
 
             if isinstance(value, db.Property):
                 dtype = value.datatype
diff --git a/src/caosadvancedtools/scifolder/withreadme.py b/src/caosadvancedtools/scifolder/withreadme.py
index 94280b80..faab94cb 100644
--- a/src/caosadvancedtools/scifolder/withreadme.py
+++ b/src/caosadvancedtools/scifolder/withreadme.py
@@ -156,8 +156,8 @@ class WithREADME(object):
                          for f in sublist]
 
             if len(flat_list) == 0:
-                LOGGER.warn("ATTENTION: the field {} does not reference any "
-                            "known files".format(field.key))
+                LOGGER.warning(f"ATTENTION: the field {field.key} does not"
+                               " reference any known files")
 
             self.attached_filenames.extend(flat_list)  # pylint: disable=no-member
 
diff --git a/src/caosadvancedtools/table_converter.py b/src/caosadvancedtools/table_converter.py
index c5fcb969..16f27476 100644
--- a/src/caosadvancedtools/table_converter.py
+++ b/src/caosadvancedtools/table_converter.py
@@ -73,7 +73,7 @@ def from_table(spreadsheet, recordtype):
     """ parses a pandas DataFrame to a list of records """
     records = db.Container()
 
-    for idx, row in spreadsheet.iterrows():
+    for _, row in spreadsheet.iterrows():
         rec = db.Record()
         rec.add_parent(name=recordtype)
 
diff --git a/src/caosadvancedtools/utils.py b/src/caosadvancedtools/utils.py
index 3e1e6992..0d73f962 100644
--- a/src/caosadvancedtools/utils.py
+++ b/src/caosadvancedtools/utils.py
@@ -235,7 +235,6 @@ def find_records_that_reference_ids(referenced_ids, rt="", step_size=50):
             record_ids.update([exp.id for exp in exps])
         except Exception as e:
             print(e)
-            pass
 
         index += step_size
 
diff --git a/src/caosadvancedtools/webui_formatter.py b/src/caosadvancedtools/webui_formatter.py
index c3c5381d..43ebbe06 100644
--- a/src/caosadvancedtools/webui_formatter.py
+++ b/src/caosadvancedtools/webui_formatter.py
@@ -92,4 +92,4 @@ class WebUI_Formatter(logging.Formatter):
             return wrap_bootstrap_alert("<b>CRITICAL ERROR:</b> " + text,
                                         kind="danger")
         else:
-            raise Exception("unknown level")
+            raise RuntimeError("unknown level")
-- 
GitLab