From 8cbd17570ad9b40eb6101c1fab8fd1716375af40 Mon Sep 17 00:00:00 2001
From: Timm Fitschen <t.fitschen@indiscale.com>
Date: Mon, 16 May 2022 21:27:40 +0200
Subject: [PATCH] MAINT: apply suggestions from pylint

---
 src/caosdb/common/models.py  | 16 +++++++++-------
 src/caosdb/common/utils.py   | 10 ++++++++++
 src/caosdb/high_level_api.py | 32 ++++++++++++++++----------------
 3 files changed, 35 insertions(+), 23 deletions(-)

diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py
index cb090098..baed2928 100644
--- a/src/caosdb/common/models.py
+++ b/src/caosdb/common/models.py
@@ -47,11 +47,12 @@ from random import randint
 from sys import hexversion
 from tempfile import NamedTemporaryFile
 from warnings import warn
+from lxml import etree
 
 from caosdb.common.datatype import (BOOLEAN, DATETIME, DOUBLE, INTEGER, TEXT,
                                     is_list_datatype, is_reference)
 from caosdb.common.state import State
-from caosdb.common.utils import uuid, xml2str
+from caosdb.common.utils import uuid, xml2str, experimental
 from caosdb.common.versioning import Version
 from caosdb.configuration import get_config
 from caosdb.connection.connection import get_connection
@@ -66,7 +67,6 @@ from caosdb.exceptions import (AmbiguousEntityError, AuthorizationError,
                                TransactionError, UniqueNamesError,
                                UnqualifiedParentsError,
                                UnqualifiedPropertiesError)
-from lxml import etree
 
 _ENTITY_URI_SEGMENT = "Entity"
 
@@ -1819,6 +1819,8 @@ class Record(Entity):
         return Entity.to_xml(self, xml, add_properties=ALL)
 
 
+@experimental("The Directory class is experimental. It should not be used \
+              until the server's file storage API has been refactored.")
 class Directory(Record):
     """This class represents CaosDB's directory entities."""
 
@@ -3104,7 +3106,7 @@ class Container(list):
 
             # legacy API - remove new directories.
             if unique and remote_entity.role is not None and remote_entity.role.lower() == "directory":
-                continue;
+                continue
 
             if not (remote_entity in used_remote_entities):
                 sync_remote_entities.append(remote_entity)
@@ -3380,10 +3382,10 @@ class Container(list):
                 uri1, uri2 = Container._split_uri_string(entities)
             except ValueError as val_e:
                 raise uri_e from val_e
-        c1 = self._retrieve(entities=uri1, flags=flags)
-        c2 = self._retrieve(entities=uri2, flags=flags)
-        c1.extend(c2)
-        c1.messages.extend(c2.messages)
+            c1 = self._retrieve(entities=uri1, flags=flags)
+            c2 = self._retrieve(entities=uri2, flags=flags)
+            c1.extend(c2)
+            c1.messages.extend(c2.messages)
 
         return c1
 
diff --git a/src/caosdb/common/utils.py b/src/caosdb/common/utils.py
index eabce313..da29e36e 100644
--- a/src/caosdb/common/utils.py
+++ b/src/caosdb/common/utils.py
@@ -27,6 +27,7 @@ from lxml import etree
 from multiprocessing import Lock
 from uuid import uuid4
 from sys import hexversion
+import warnings
 _uuid_lock = Lock()
 
 
@@ -55,3 +56,12 @@ def is_int(obj):
         return True
     except ValueError:
         return False
+
+
+def experimental(message):
+    def decorator(decorated):
+        def caller(*args, **kwargs):
+            warnings.warn(message, UserWarning, stacklevel=3)
+            return decorated(*args, **kwargs)
+        return caller
+    return decorator
diff --git a/src/caosdb/high_level_api.py b/src/caosdb/high_level_api.py
index 0c936112..86b811e2 100644
--- a/src/caosdb/high_level_api.py
+++ b/src/caosdb/high_level_api.py
@@ -60,23 +60,23 @@ def standard_type_for_high_level_type(high_level_record: "CaosDBPythonEntity",
     class in the standard CaosDB API or - if return_string is True - return
     the role as a string.
     """
-    if type(high_level_record) == CaosDBPythonRecord:
+    if isinstance(high_level_record, CaosDBPythonRecord):
         if not return_string:
             return db.Record
         return "Record"
-    elif type(high_level_record) == CaosDBPythonFile:
+    elif isinstance(high_level_record, CaosDBPythonFile):
         if not return_string:
             return db.File
         return "File"
-    elif type(high_level_record) == CaosDBPythonProperty:
+    elif isinstance(high_level_record, CaosDBPythonProperty):
         if not return_string:
             return db.Property
         return "Property"
-    elif type(high_level_record) == CaosDBPythonRecordType:
+    elif isinstance(high_level_record, CaosDBPythonRecordType):
         if not return_string:
             return db.RecordType
         return "RecordType"
-    elif type(high_level_record) == CaosDBPythonEntity:
+    elif isinstance(high_level_record, CaosDBPythonEntity):
         if not return_string:
             return db.Entity
         return "Entity"
@@ -101,15 +101,15 @@ def high_level_type_for_standard_type(standard_record: db.Entity):
     if not isinstance(standard_record, db.Entity):
         raise ValueError()
     role = standard_record.role
-    if role == "Record" or type(standard_record) == db.Record:
+    if role == "Record" or isinstance(standard_record, db.Record):
         return CaosDBPythonRecord
-    elif role == "File" or type(standard_record) == db.File:
+    elif role == "File" or isinstance(standard_record, db.File):
         return CaosDBPythonFile
-    elif role == "Property" or type(standard_record) == db.Property:
+    elif role == "Property" or isinstance(standard_record, db.Property):
         return CaosDBPythonProperty
-    elif role == "RecordType" or type(standard_record) == db.RecordType:
+    elif role == "RecordType" or isinstance(standard_record, db.RecordType):
         return CaosDBPythonRecordType
-    elif role == "Entity" or type(standard_record) == db.Entity:
+    elif role == "Entity" or isinstance(standard_record, db.Entity):
         return CaosDBPythonEntity
     raise RuntimeError("Incompatible type.")
 
@@ -213,14 +213,14 @@ class CaosDBPythonEntity(object):
         """
         Getter for the file.
         """
-        if type(self) != CaosDBPythonFile:
+        if not isinstance(self, CaosDBPythonFile):
             raise RuntimeError("Please don't use the file attribute for entities"
                                " that are no files.")
         return self._file
 
     @file.setter
     def file(self, val: str):
-        if val is not None and type(self) != CaosDBPythonFile:
+        if val is not None and not isinstance(self, CaosDBPythonFile):
             raise RuntimeError("Please don't use the file attribute for entities"
                                " that are no files.")
         self._file = val
@@ -230,14 +230,14 @@ class CaosDBPythonEntity(object):
         """
         Getter for the path.
         """
-        if type(self) != CaosDBPythonFile:
+        if not isinstance(self, CaosDBPythonFile):
             raise RuntimeError("Please don't use the path attribute for entities"
                                " that are no files.")
         return self._path
 
     @path.setter
     def path(self, val: str):
-        if val is not None and type(self) != CaosDBPythonFile:
+        if val is not None and not isinstance(self, CaosDBPythonFile):
             raise RuntimeError("Please don't use the path attribute for entities"
                                " that are no files.")
         self._path = val
@@ -646,7 +646,7 @@ class CaosDBPythonEntity(object):
             if baseprop in serialization:
                 entity.__setattr__(baseprop, serialization[baseprop])
 
-        if type(entity) == CaosDBPythonFile:
+        if isinstance(entity, CaosDBPythonFile):
             entity.file = serialization["file"]
             entity.path = serialization["path"]
 
@@ -717,7 +717,7 @@ class CaosDBPythonEntity(object):
             if val is not None:
                 fulldict[baseprop] = val
 
-        if type(self) == CaosDBPythonFile:
+        if isinstance(self, CaosDBPythonFile):
             fulldict["file"] = self.file
             fulldict["path"] = self.path
 
-- 
GitLab