This is an automated email from the ASF dual-hosted git repository.

jin pushed a commit to branch py-client-new
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph-ai.git


The following commit(s) were added to refs/heads/py-client-new by this push:
     new 7b84f21  chore(client): fix pylint (#66)
7b84f21 is described below

commit 7b84f218d1bc5578d661d4e8c6bd72f84d3d5c9d
Author: PeiChaoXu <[email protected]>
AuthorDate: Thu Aug 15 00:58:18 2024 +0800

    chore(client): fix pylint (#66)
    
    merge to master now
    ---------
    
    Co-authored-by: imbajin <[email protected]>
    Co-authored-by: blank <[email protected]>
---
 hugegraph-python-client/src/pyhugegraph/api/graph.py   |  8 ++++----
 hugegraph-python-client/src/pyhugegraph/api/rebuild.py |  6 +++---
 .../src/pyhugegraph/api/schema_manage/edge_label.py    |  6 ++++--
 .../src/pyhugegraph/api/schema_manage/index_label.py   | 18 +++++++++---------
 .../src/pyhugegraph/api/schema_manage/property_key.py  |  9 ++++++---
 .../src/pyhugegraph/api/schema_manage/vertex_label.py  | 14 +++++++++-----
 .../src/pyhugegraph/api/services.py                    |  6 +++---
 hugegraph-python-client/src/pyhugegraph/client.py      |  2 +-
 .../src/pyhugegraph/structure/rank_data.py             |  2 +-
 .../src/pyhugegraph/utils/huge_config.py               |  8 ++++----
 .../src/pyhugegraph/utils/huge_requests.py             | 12 ++++++------
 hugegraph-python-client/src/pyhugegraph/utils/log.py   | 14 ++++++++------
 hugegraph-python-client/src/pyhugegraph/utils/util.py  |  7 ++++---
 13 files changed, 62 insertions(+), 50 deletions(-)

diff --git a/hugegraph-python-client/src/pyhugegraph/api/graph.py 
b/hugegraph-python-client/src/pyhugegraph/api/graph.py
index f410404..907e01a 100644
--- a/hugegraph-python-client/src/pyhugegraph/api/graph.py
+++ b/hugegraph-python-client/src/pyhugegraph/api/graph.py
@@ -16,11 +16,11 @@
 # under the License.
 
 import json
-
 from typing import Optional, List
+
 from pyhugegraph.api.common import HugeParamsBase
-from pyhugegraph.structure.vertex_data import VertexData
 from pyhugegraph.structure.edge_data import EdgeData
+from pyhugegraph.structure.vertex_data import VertexData
 from pyhugegraph.utils import huge_router as router
 from pyhugegraph.utils.exceptions import NotFoundError
 
@@ -205,7 +205,7 @@ class GraphManager(HugeParamsBase):
             return []
         path = "traversers/vertices?"
         for vertex_id in vertex_ids:
-            path += f'ids="{vertex_id}"&'
+            path += f'ids="{vertex_id}"&'  # pylint: 
disable=consider-using-join
         path = path.rstrip("&")
         if response := self._sess.request(path):
             return [VertexData(item) for item in response["vertices"]]
@@ -216,7 +216,7 @@ class GraphManager(HugeParamsBase):
             return []
         path = "traversers/edges?"
         for vertex_id in edge_ids:
-            path += f"ids={vertex_id}&"
+            path += f"ids={vertex_id}&"  # pylint: disable=consider-using-join
         path = path.rstrip("&")
         if response := self._sess.request(path):
             return [EdgeData(item) for item in response["edges"]]
diff --git a/hugegraph-python-client/src/pyhugegraph/api/rebuild.py 
b/hugegraph-python-client/src/pyhugegraph/api/rebuild.py
index e0b4d64..74075f8 100644
--- a/hugegraph-python-client/src/pyhugegraph/api/rebuild.py
+++ b/hugegraph-python-client/src/pyhugegraph/api/rebuild.py
@@ -47,7 +47,7 @@ class RebuildManager(HugeParamsBase):
             dict: A dictionary containing the response from the HTTP request.
                   The structure of the response is as follows:
                   response = {
-                      "task_id": 1  # Unique identifier for the task.
+                      "task_id": 1 # Unique identifier for the task.
                   }
         """
         return self._invoke_request()
@@ -64,7 +64,7 @@ class RebuildManager(HugeParamsBase):
             dict: A dictionary containing the response from the HTTP request.
                   The structure of the response is as follows:
                   response = {
-                      "task_id": 1  # Unique identifier for the task.
+                      "task_id": 1 # Unique identifier for the task.
                   }
         """
         return self._invoke_request()
@@ -81,7 +81,7 @@ class RebuildManager(HugeParamsBase):
             dict: A dictionary containing the response from the HTTP request.
                   The structure of the response is as follows:
                   response = {
-                      "task_id": 1  # Unique identifier for the task.
+                      "task_id": 1 # Unique identifier for the task.
                   }
         """
         return self._invoke_request()
diff --git 
a/hugegraph-python-client/src/pyhugegraph/api/schema_manage/edge_label.py 
b/hugegraph-python-client/src/pyhugegraph/api/schema_manage/edge_label.py
index 37b8564..636a564 100644
--- a/hugegraph-python-client/src/pyhugegraph/api/schema_manage/edge_label.py
+++ b/hugegraph-python-client/src/pyhugegraph/api/schema_manage/edge_label.py
@@ -15,12 +15,14 @@
 # specific language governing permissions and limitations
 # under the License.
 
+# pylint: disable=logging-fstring-interpolation
+
 import json
 
 from pyhugegraph.api.common import HugeParamsBase
-from pyhugegraph.utils.util import ResponseValidation
-from pyhugegraph.utils.huge_decorator import decorator_params, decorator_create
+from pyhugegraph.utils.huge_decorator import decorator_create, decorator_params
 from pyhugegraph.utils.log import log
+from pyhugegraph.utils.util import ResponseValidation
 
 
 class EdgeLabel(HugeParamsBase):
diff --git 
a/hugegraph-python-client/src/pyhugegraph/api/schema_manage/index_label.py 
b/hugegraph-python-client/src/pyhugegraph/api/schema_manage/index_label.py
index 1437177..252d487 100644
--- a/hugegraph-python-client/src/pyhugegraph/api/schema_manage/index_label.py
+++ b/hugegraph-python-client/src/pyhugegraph/api/schema_manage/index_label.py
@@ -15,13 +15,14 @@
 # specific language governing permissions and limitations
 # under the License.
 
-import json
+# pylint: disable=logging-fstring-interpolation
 
+import json
 
 from pyhugegraph.api.common import HugeParamsBase
-from pyhugegraph.utils.util import ResponseValidation
-from pyhugegraph.utils.huge_decorator import decorator_params, decorator_create
+from pyhugegraph.utils.huge_decorator import decorator_create, decorator_params
 from pyhugegraph.utils.log import log
+from pyhugegraph.utils.util import ResponseValidation
 
 
 class IndexLabel(HugeParamsBase):
@@ -82,12 +83,11 @@ class IndexLabel(HugeParamsBase):
     @decorator_create
     def create(self):
         dic = self._parameter_holder.get_dic()
-        data = {}
-        data["name"] = dic["name"]
-        data["base_type"] = dic["base_type"]
-        data["base_value"] = dic["base_value"]
-        data["index_type"] = dic["index_type"]
-        data["fields"] = list(dic["fields"])
+        data = {"name": dic["name"],
+                "base_type": dic["base_type"],
+                "base_value": dic["base_value"],
+                "index_type": dic["index_type"],
+                "fields": list(dic["fields"])}
         path = "schema/indexlabels"
         self.clean_parameter_holder()
         if response := self._sess.request(path, "POST", data=json.dumps(data)):
diff --git 
a/hugegraph-python-client/src/pyhugegraph/api/schema_manage/property_key.py 
b/hugegraph-python-client/src/pyhugegraph/api/schema_manage/property_key.py
index 38f5bd9..7ee5d44 100644
--- a/hugegraph-python-client/src/pyhugegraph/api/schema_manage/property_key.py
+++ b/hugegraph-python-client/src/pyhugegraph/api/schema_manage/property_key.py
@@ -17,11 +17,10 @@
 
 import json
 
-
 from pyhugegraph.api.common import HugeParamsBase
-from pyhugegraph.utils.util import ResponseValidation
-from pyhugegraph.utils.huge_decorator import decorator_params, decorator_create
+from pyhugegraph.utils.huge_decorator import decorator_create, decorator_params
 from pyhugegraph.utils.log import log
+from pyhugegraph.utils.util import ResponseValidation
 
 
 class PropertyKey(HugeParamsBase):
@@ -117,6 +116,7 @@ class PropertyKey(HugeParamsBase):
         if response := self._sess.request(path, "POST", 
data=json.dumps(property_keys)):
             return f"create PropertyKey success, Detail: {str(response)}"
         log.error("create PropertyKey failed, Detail: %s", str(response))
+        return ""
 
     @decorator_params
     def append(self):
@@ -131,6 +131,7 @@ class PropertyKey(HugeParamsBase):
         if response := self._sess.request(path, "PUT", data=json.dumps(data)):
             return f"append PropertyKey success, Detail: {str(response)}"
         log.error("append PropertyKey failed, Detail: %s", str(response))
+        return ""
 
     @decorator_params
     def eliminate(self):
@@ -145,6 +146,7 @@ class PropertyKey(HugeParamsBase):
         if response := self._sess.request(path, "PUT", data=json.dumps(data)):
             return f"eliminate PropertyKey success, Detail: {str(response)}"
         log.error("eliminate PropertyKey failed, Detail: %s", str(response))
+        return ""
 
     @decorator_params
     def remove(self):
@@ -154,3 +156,4 @@ class PropertyKey(HugeParamsBase):
         if response := self._sess.request(path, "DELETE"):
             return f"delete PropertyKey success, Detail: {str(response)}"
         log.error("delete PropertyKey failed, Detail: %s", str(response))
+        return ""
diff --git 
a/hugegraph-python-client/src/pyhugegraph/api/schema_manage/vertex_label.py 
b/hugegraph-python-client/src/pyhugegraph/api/schema_manage/vertex_label.py
index 610d214..597fb6f 100644
--- a/hugegraph-python-client/src/pyhugegraph/api/schema_manage/vertex_label.py
+++ b/hugegraph-python-client/src/pyhugegraph/api/schema_manage/vertex_label.py
@@ -18,9 +18,9 @@
 import json
 
 from pyhugegraph.api.common import HugeParamsBase
-from pyhugegraph.utils.util import ResponseValidation
-from pyhugegraph.utils.huge_decorator import decorator_params, decorator_create
+from pyhugegraph.utils.huge_decorator import decorator_create, decorator_params
 from pyhugegraph.utils.log import log
+from pyhugegraph.utils.util import ResponseValidation
 
 
 class VertexLabel(HugeParamsBase):
@@ -104,9 +104,10 @@ class VertexLabel(HugeParamsBase):
         if response := self._sess.request(path, "POST", data=json.dumps(data)):
             return f'create VertexLabel success, Detail: "{str(response)}"'
         log.error("create VertexLabel failed, Detail: %s", str(response))
+        return ""
 
     @decorator_params
-    def append(self):
+    def append(self) -> None:
         dic = self._parameter_holder.get_dic()
         properties = dic["properties"] if "properties" in dic else []
         nullable_keys = dic["nullable_keys"] if "nullable_keys" in dic else []
@@ -122,18 +123,20 @@ class VertexLabel(HugeParamsBase):
         if response := self._sess.request(path, "PUT", data=json.dumps(data)):
             return f'append VertexLabel success, Detail: "{str(response)}"'
         log.error("append VertexLabel failed, Detail: %s", str(response))
+        return ""
 
     @decorator_params
-    def remove(self):
+    def remove(self) -> None:
         name = self._parameter_holder.get_value("name")
         path = f"schema/vertexlabels/{name}"
         self.clean_parameter_holder()
         if response := self._sess.request(path, "DELETE"):
             return f'remove VertexLabel success, Detail: "{str(response)}"'
         log.error("remove VertexLabel failed, Detail: %s", str(response))
+        return ""
 
     @decorator_params
-    def eliminate(self):
+    def eliminate(self) -> None:
         name = self._parameter_holder.get_value("name")
         path = f"schema/vertexlabels/{name}/?action=eliminate"
 
@@ -146,3 +149,4 @@ class VertexLabel(HugeParamsBase):
         if response := self._sess.request(path, "PUT", data=json.dumps(data)):
             return f'eliminate VertexLabel success, Detail: "{str(response)}"'
         log.error("eliminate VertexLabel failed, Detail: %s", str(response))
+        return ""
diff --git a/hugegraph-python-client/src/pyhugegraph/api/services.py 
b/hugegraph-python-client/src/pyhugegraph/api/services.py
index 0c2c0a7..e086ae1 100644
--- a/hugegraph-python-client/src/pyhugegraph/api/services.py
+++ b/hugegraph-python-client/src/pyhugegraph/api/services.py
@@ -40,11 +40,11 @@ class ServicesManager(HugeParamsBase):
             Returns a dictionary containing a list of service names.
 
         get_service(graphspace: str, service: str):
-            Retrieves detailed information about a specific service within a 
graph space.
+            Retrieve detailed information about a specific service within a 
graph space.
             Returns a dictionary with the service details.
 
         delete_service(graphspace: str, service: str):
-            Deletes a specific service within a graph space after confirmation.
+            Delete a specific service within a graph space after confirmation.
             No return value expected; the operation's success is indicated by 
an HTTP 204 status code.
     """
 
@@ -68,7 +68,7 @@ class ServicesManager(HugeParamsBase):
     @router.http("GET", "/graphspaces/${graphspace}/services")
     def list_services(self, graphspace: str):  # pylint: 
disable=unused-argument
         """
-        List all services in a specified graph space..
+        List all services in a specified graph space.
 
         Args:
             graphspace (str): The name of the graph space to list services 
from.
diff --git a/hugegraph-python-client/src/pyhugegraph/client.py 
b/hugegraph-python-client/src/pyhugegraph/client.py
index b740e89..c854714 100644
--- a/hugegraph-python-client/src/pyhugegraph/client.py
+++ b/hugegraph-python-client/src/pyhugegraph/client.py
@@ -49,7 +49,7 @@ class PyHugeClient:
     def __init__(
         self,
         ip: str,
-        port: str,
+        port: str, # TODO: port should be int?
         graph: str,
         user: str,
         pwd: str,
diff --git a/hugegraph-python-client/src/pyhugegraph/structure/rank_data.py 
b/hugegraph-python-client/src/pyhugegraph/structure/rank_data.py
index e4adc32..af622c9 100644
--- a/hugegraph-python-client/src/pyhugegraph/structure/rank_data.py
+++ b/hugegraph-python-client/src/pyhugegraph/structure/rank_data.py
@@ -24,7 +24,7 @@ from dataclasses import asdict, dataclass, field
 @dataclass
 class NeighborRankStep:
     """
-    Steps object defines the traversal path rules from the starting vertex.
+    Step object defines the traversal path rules from the starting vertex.
     """
 
     direction: str = "BOTH"
diff --git a/hugegraph-python-client/src/pyhugegraph/utils/huge_config.py 
b/hugegraph-python-client/src/pyhugegraph/utils/huge_config.py
index fc5e1c7..f7cb2d9 100644
--- a/hugegraph-python-client/src/pyhugegraph/utils/huge_config.py
+++ b/hugegraph-python-client/src/pyhugegraph/utils/huge_config.py
@@ -16,11 +16,11 @@
 # under the License.
 
 import re
-import requests
 import traceback
-
 from dataclasses import dataclass, field
-from typing import Optional, List
+from typing import List, Optional
+
+import requests
 from pyhugegraph.utils.log import log
 
 
@@ -38,7 +38,7 @@ class HGraphConfig:
 
     def __post_init__(self):
 
-        if self.graphspace is not None:
+        if self.graphspace and self.graphspace.strip():
             self.gs_supported = True
 
         else:
diff --git a/hugegraph-python-client/src/pyhugegraph/utils/huge_requests.py 
b/hugegraph-python-client/src/pyhugegraph/utils/huge_requests.py
index e983fcb..3cfe625 100644
--- a/hugegraph-python-client/src/pyhugegraph/utils/huge_requests.py
+++ b/hugegraph-python-client/src/pyhugegraph/utils/huge_requests.py
@@ -16,16 +16,16 @@
 # under the License.
 
 
-from urllib3.util.retry import Retry
-from urllib.parse import urljoin
 from typing import Any, Optional
-from requests.adapters import HTTPAdapter
+from urllib.parse import urljoin
+
+import requests
 from pyhugegraph.utils.constants import Constants
 from pyhugegraph.utils.huge_config import HGraphConfig
-from pyhugegraph.utils.util import ResponseValidation
 from pyhugegraph.utils.log import log
-
-import requests
+from pyhugegraph.utils.util import ResponseValidation
+from requests.adapters import HTTPAdapter
+from urllib3.util.retry import Retry
 
 
 class HGraphSession:
diff --git a/hugegraph-python-client/src/pyhugegraph/utils/log.py 
b/hugegraph-python-client/src/pyhugegraph/utils/log.py
index 2f5153f..157d26c 100755
--- a/hugegraph-python-client/src/pyhugegraph/utils/log.py
+++ b/hugegraph-python-client/src/pyhugegraph/utils/log.py
@@ -14,15 +14,15 @@
 #  limitations under the License.
 
 import logging
-from logging.handlers import TimedRotatingFileHandler
 import os
+from logging.handlers import TimedRotatingFileHandler
 
 # Set log format
 LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
 DATE_FORMAT = "%Y-%m-%d %H:%M:%S %p"
 
 
-# Function to configure logging path, default is "logs/output.log"
+# Function to configure the logging path, default is "logs/output.log"
 # You could import it in "__init__.py" & use it in the whole package
 def init_log(log_file="logs/output.log"):
     # Ensure the log directory exists
@@ -30,10 +30,10 @@ def init_log(log_file="logs/output.log"):
     os.makedirs(log_dir, exist_ok=True)
 
     # Create a logger
-    log = logging.getLogger(__name__)
+    log = logging.getLogger(__name__)  # pylint: disable=redefined-outer-name
     log.setLevel(logging.INFO)
 
-    # Create a handler for writing to log file
+    # Create a handler for writing to log files
     file_handler = TimedRotatingFileHandler(
         log_file, when="midnight", interval=1, backupCount=3, encoding="utf-8"
     )
@@ -60,9 +60,11 @@ def init_log(log_file="logs/output.log"):
                 stream = self.stream
                 stream.write(color_prefix + msg + color_suffix + 
self.terminator)
                 self.flush()
-            except Exception as e:
+            except Exception as e:  # pylint: disable=broad-exception-caught
                 self.handleError(record)
-                log.error(f"Log Print Exception: {e}")
+                log.error(  # pylint: disable=logging-fstring-interpolation
+                    f"Log Print Exception: {e}"
+                )
 
     # Also output logs to the console
     custom_handler = CustomConsoleHandler()
diff --git a/hugegraph-python-client/src/pyhugegraph/utils/util.py 
b/hugegraph-python-client/src/pyhugegraph/utils/util.py
index 256b672..d90e6ba 100644
--- a/hugegraph-python-client/src/pyhugegraph/utils/util.py
+++ b/hugegraph-python-client/src/pyhugegraph/utils/util.py
@@ -15,14 +15,15 @@
 # specific language governing permissions and limitations
 # under the License.
 
+
 import json
 import traceback
-import requests
 
+import requests
 from pyhugegraph.utils.exceptions import (
-    ServiceUnavailableException,
     NotAuthorizedError,
     NotFoundError,
+    ServiceUnavailableException,
 )
 from pyhugegraph.utils.log import log
 
@@ -111,7 +112,7 @@ class ResponseValidation:
                     details = "key 'exception' not found"
 
                 log.error(  # pylint: disable=logging-fstring-interpolation
-                    f"{method}: {e}; Server Exception: {details}"
+                    f"{method}: {e}\n[Body]: {response.request.body}\n[Server 
Exception]: {details}"
                 )
 
                 if response.status_code == 404:

Reply via email to