From beb341cd07ac1e9e3dba8912ea143f01f90c53e0 Mon Sep 17 00:00:00 2001 From: Yanli Date: Thu, 11 Dec 2025 17:59:19 +0800 Subject: [PATCH] run ruff and fix lint --- .github/workflows/update_version.py | 16 +++++++++++----- docs/7_orm_example.py | 4 +++- example.py | 1 + scripts/add_apache_headers.py | 1 - src/nebulagraph_python/decoder/size_constant.py | 4 ++-- src/nebulagraph_python/orm/model.py | 2 +- src/nebulagraph_python/py_data_types.py | 5 ++++- src/nebulagraph_python/result_set.py | 2 +- src/nebulagraph_python/value_wrapper.py | 3 +++ 9 files changed, 26 insertions(+), 12 deletions(-) diff --git a/.github/workflows/update_version.py b/.github/workflows/update_version.py index d8c0b89f..1d346624 100644 --- a/.github/workflows/update_version.py +++ b/.github/workflows/update_version.py @@ -7,7 +7,9 @@ from typing import Optional -def update_version(version_type: str = "dev", custom_suffix: Optional[str] = None) -> str: +def update_version( + version_type: str = "dev", custom_suffix: Optional[str] = None +) -> str: """ Update the `version` field in `pyproject.toml` for supported manual build types. @@ -25,17 +27,21 @@ def update_version(version_type: str = "dev", custom_suffix: Optional[str] = Non content: str = pyproject_path.read_text() # Extract current version - version_match: Optional[re.Match[str]] = re.search(r'^version\s*=\s*"([^"]+)"', content, re.MULTILINE) + version_match: Optional[re.Match[str]] = re.search( + r'^version\s*=\s*"([^"]+)"', content, re.MULTILINE + ) if not version_match: raise ValueError("Could not find version in pyproject.toml") current_version: str = version_match.group(1) - + # Parse the base version (remove any existing suffixes) - base_version_match: Optional[re.Match[str]] = re.match(r'^(\d+\.\d+\.\d+)', current_version) + base_version_match: Optional[re.Match[str]] = re.match( + r"^(\d+\.\d+\.\d+)", current_version + ) if not base_version_match: raise ValueError(f"Invalid version format: {current_version}") - + base_version: str = base_version_match.group(1) # Only dev/custom builds mutate the version; all others keep current version diff --git a/docs/7_orm_example.py b/docs/7_orm_example.py index 58ed9065..1c40ddec 100644 --- a/docs/7_orm_example.py +++ b/docs/7_orm_example.py @@ -117,7 +117,9 @@ class Edge1( if input("Execute the DDL? (y/N)") == "y": client.execute_py(graph_type.to_gql()) - client.execute_py("CREATE GRAPH IF NOT EXISTS define_type_test define_type_test_type") + client.execute_py( + "CREATE GRAPH IF NOT EXISTS define_type_test define_type_test_type" + ) q = upsert_gql( diff --git a/example.py b/example.py index 7d55897e..ee1e8165 100644 --- a/example.py +++ b/example.py @@ -187,6 +187,7 @@ def sync_session_pool_example(): if __name__ == "__main__": import asyncio import logging + logging.basicConfig(level=logging.DEBUG) logging.getLogger("nebulagraph_python").setLevel(logging.DEBUG) diff --git a/scripts/add_apache_headers.py b/scripts/add_apache_headers.py index 8f4357a0..5aa13dd2 100644 --- a/scripts/add_apache_headers.py +++ b/scripts/add_apache_headers.py @@ -203,4 +203,3 @@ def main() -> None: if __name__ == "__main__": main() - diff --git a/src/nebulagraph_python/decoder/size_constant.py b/src/nebulagraph_python/decoder/size_constant.py index 00769564..0760782c 100644 --- a/src/nebulagraph_python/decoder/size_constant.py +++ b/src/nebulagraph_python/decoder/size_constant.py @@ -25,8 +25,8 @@ BOOL_SIZE = 1 # Vector element size EMBEDDING_VECTOR_DIM_SIZE = 4 # Size of vector dimension in row type (int32) -ELEMENT_NUMBER_SIZE_FOR_VECTOR_VALUE=2 -EMBEDDING_VECTOR_FLOAT_VALUE_SIZE=4 +ELEMENT_NUMBER_SIZE_FOR_VECTOR_VALUE = 2 +EMBEDDING_VECTOR_FLOAT_VALUE_SIZE = 4 FLOAT32_SIZE = 4 # Size of each float32 element in vector # String size: 4 byte string value length + 4 byte prefix string diff --git a/src/nebulagraph_python/orm/model.py b/src/nebulagraph_python/orm/model.py index 58820c48..1b2068bc 100644 --- a/src/nebulagraph_python/orm/model.py +++ b/src/nebulagraph_python/orm/model.py @@ -12,11 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +from collections.abc import Sequence as ABCSequence from dataclasses import dataclass from datetime import date from types import UnionType from typing import Iterable -from collections.abc import Sequence as ABCSequence from pydantic import ( AfterValidator, diff --git a/src/nebulagraph_python/py_data_types.py b/src/nebulagraph_python/py_data_types.py index 840fadeb..11e15070 100644 --- a/src/nebulagraph_python/py_data_types.py +++ b/src/nebulagraph_python/py_data_types.py @@ -902,7 +902,7 @@ def __eq__(self, other) -> bool: logger.warning("Expected Vector, got %s", type(other)) return False return self.dimension == other.dimension and all( - abs(a - b) < 1e-7 for a, b in zip(self.values, other.values) + abs(a - b) < 1e-7 for a, b in zip(self.values, other.values, strict=True) ) def __str__(self) -> str: @@ -913,6 +913,9 @@ def __repr__(self) -> str: """Return detailed string representation of the vector.""" return f"NVector({self.values})" + def __hash__(self) -> int: + return hash(str(self)) + BasicTargetType = Union[ None, diff --git a/src/nebulagraph_python/result_set.py b/src/nebulagraph_python/result_set.py index 2c0b0f28..26e1fca0 100644 --- a/src/nebulagraph_python/result_set.py +++ b/src/nebulagraph_python/result_set.py @@ -392,7 +392,7 @@ def as_ascii_table( row_num = 1 for record in self.records(): console.print(f"\n[bold blue]Row {row_num}[/bold blue]") - for col, val in zip(self.column_names, record.values()): + for col, val in zip(self.column_names, record.values(), strict=True): console.print(f" [cyan]{col}:[/cyan] {val.cast_primitive()}") row_num += 1 diff --git a/src/nebulagraph_python/value_wrapper.py b/src/nebulagraph_python/value_wrapper.py index ee15d660..78000c21 100644 --- a/src/nebulagraph_python/value_wrapper.py +++ b/src/nebulagraph_python/value_wrapper.py @@ -357,6 +357,9 @@ def __eq__(self, other): return False return self.value == other.value and self.data_type == other.data_type + def __hash__(self) -> int: + return hash((self.value, self.data_type)) + class Row: def __init__(self, values: Optional[List[ValueWrapper]] = None):