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

chaokunyang pushed a commit to branch releases-0.12
in repository https://gitbox.apache.org/repos/asf/fory.git

commit 8a5bfed45325b305586ab1fa56604f9926a05ba4
Author: chaokunyang <[email protected]>
AuthorDate: Sat Sep 20 00:51:41 2025 +0800

    lint code
---
 python/pyfory/_fory.py                     |  2 +-
 python/pyfory/_struct.py                   |  1 -
 python/pyfory/format/__init__.py           |  3 +--
 python/pyfory/format/tests/test_encoder.py |  8 ++------
 python/pyfory/serializer.py                |  2 --
 python/pyfory/tests/benchmark.py           | 20 ++++----------------
 python/pyfory/tests/record.py              |  4 +---
 python/pyfory/tests/test_buffer.py         |  5 +----
 python/pyfory/tests/test_codegen.py        |  4 +---
 python/pyfory/tests/test_metastring.py     |  4 +---
 python/pyfory/tests/test_serializer.py     |  1 -
 python/pyfory/type.py                      | 20 ++++----------------
 12 files changed, 16 insertions(+), 58 deletions(-)

diff --git a/python/pyfory/_fory.py b/python/pyfory/_fory.py
index 2894fe7a9..3900c2bf2 100644
--- a/python/pyfory/_fory.py
+++ b/python/pyfory/_fory.py
@@ -456,7 +456,7 @@ class Fory:
         typeinfo.serializer.write(buffer, value)
 
     def read_ref_pyobject(self, buffer):
-        return self.deserialize_ref(buffer)    
+        return self.deserialize_ref(buffer)
 
     def inc_depth(self):
         self.depth += 1
diff --git a/python/pyfory/_struct.py b/python/pyfory/_struct.py
index dd7b91add..1b6f32f18 100644
--- a/python/pyfory/_struct.py
+++ b/python/pyfory/_struct.py
@@ -90,7 +90,6 @@ class ComplexTypeVisitor(TypeVisitor):
         return None
 
     def visit_other(self, field_name, type_, types_path=None):
-
         if is_subclass(type_, enum.Enum):
             return self.fory.type_resolver.get_serializer(type_)
         if type_ not in basic_types and not is_py_array_type(type_):
diff --git a/python/pyfory/format/__init__.py b/python/pyfory/format/__init__.py
index 3bc70502f..f6fd1d8f5 100644
--- a/python/pyfory/format/__init__.py
+++ b/python/pyfory/format/__init__.py
@@ -41,8 +41,7 @@ try:
     )
 except (ImportError, AttributeError) as e:
     warnings.warn(
-        f"Fory format initialization failed, please ensure pyarrow is 
installed "
-        f"with version which fory is compiled with: {e}",
+        f"Fory format initialization failed, please ensure pyarrow is 
installed with version which fory is compiled with: {e}",
         RuntimeWarning,
         stacklevel=2,
     )
diff --git a/python/pyfory/format/tests/test_encoder.py 
b/python/pyfory/format/tests/test_encoder.py
index ac9dbdfdc..b4b01fc1c 100644
--- a/python/pyfory/format/tests/test_encoder.py
+++ b/python/pyfory/format/tests/test_encoder.py
@@ -63,9 +63,7 @@ def test_encoder_with_schema():
 @require_pyarrow
 def test_dict():
     dict_ = {"f1": 1, "f2": "str"}
-    encoder = pyfory.create_row_encoder(
-        pa.schema([("f1", pa.int32()), ("f2", pa.utf8())])
-    )
+    encoder = pyfory.create_row_encoder(pa.schema([("f1", pa.int32()), ("f2", 
pa.utf8())]))
     row = encoder.to_row(dict_)
     new_obj = encoder.from_row(row)
     assert new_obj.f1 == dict_["f1"]
@@ -74,9 +72,7 @@ def test_dict():
 
 @require_pyarrow
 def test_ints():
-    cls = pyfory.record_class_factory(
-        "TestNumeric", ["f" + str(i) for i in range(1, 9)]
-    )
+    cls = pyfory.record_class_factory("TestNumeric", ["f" + str(i) for i in 
range(1, 9)])
     schema = pa.schema(
         [
             ("f1", pa.int64()),
diff --git a/python/pyfory/serializer.py b/python/pyfory/serializer.py
index 6e211fb89..d478eb9ec 100644
--- a/python/pyfory/serializer.py
+++ b/python/pyfory/serializer.py
@@ -17,7 +17,6 @@
 
 import array
 import builtins
-import dataclasses
 import importlib
 import inspect
 import itertools
@@ -435,7 +434,6 @@ class DataClassSerializer(Serializer):
         context["_field_names"] = self._field_names
         context["_type_hints"] = self._type_hints
         context["_serializers"] = self._serializers
-        current_class_field_names = set(self._get_field_names(self.type_))
         stmts = [
             f'"""xread method for {self.type_}"""',
         ]
diff --git a/python/pyfory/tests/benchmark.py b/python/pyfory/tests/benchmark.py
index ab6abe1b7..75c883296 100644
--- a/python/pyfory/tests/benchmark.py
+++ b/python/pyfory/tests/benchmark.py
@@ -33,13 +33,9 @@ def test_encode():
     assert foo == encoder.from_row(row)
 
     t1 = timeit.timeit(lambda: encoder.to_row(foo), number=iter_nums)
-    print(
-        "encoder take {0} for {1} times, avg: {2}".format(t1, iter_nums, t1 / 
iter_nums)
-    )
+    print("encoder take {0} for {1} times, avg: {2}".format(t1, iter_nums, t1 
/ iter_nums))
     t2 = timeit.timeit(lambda: pickle.dumps(foo), number=iter_nums)
-    print(
-        "pickle take {0} for {1} times, avg: {2}".format(t2, iter_nums, t2 / 
iter_nums)
-    )
+    print("pickle take {0} for {1} times, avg: {2}".format(t2, iter_nums, t2 / 
iter_nums))
 
 
 @pytest.mark.skip(reason="take too long")
@@ -51,18 +47,10 @@ def test_decode():
     row = encoder.to_row(foo)
     assert foo == encoder.from_row(row)
     t1 = timeit.timeit(lambda: encoder.from_row(row), number=iter_nums)
-    print(
-        "encoder take {0} for {1} times, avg: {2}, size {3}".format(
-            t1, iter_nums, t1 / iter_nums, row.size_bytes()
-        )
-    )
+    print("encoder take {0} for {1} times, avg: {2}, size {3}".format(t1, 
iter_nums, t1 / iter_nums, row.size_bytes()))
     pickled_data = pickle.dumps(foo)
     t2 = timeit.timeit(lambda: pickle.loads(pickled_data), number=iter_nums)
-    print(
-        "pickle take {0} for {1} times, avg: {2}, size {3}".format(
-            t2, iter_nums, t2 / iter_nums, len(pickled_data)
-        )
-    )
+    print("pickle take {0} for {1} times, avg: {2}, size {3}".format(t2, 
iter_nums, t2 / iter_nums, len(pickled_data)))
 
 
 if __name__ == "__main__":
diff --git a/python/pyfory/tests/record.py b/python/pyfory/tests/record.py
index 2f56a9ad8..31ebd66a8 100644
--- a/python/pyfory/tests/record.py
+++ b/python/pyfory/tests/record.py
@@ -117,9 +117,7 @@ def foo_schema():
             ("f4", pa.map_(pa.string(), pa.int32())),
             ("f5", pa.list_(pa.int32())),
             ("f6", pa.int32()),
-            pa.field(
-                "f7", bar_struct, metadata={"cls": 
fory.get_qualified_classname(Bar)}
-            ),
+            pa.field("f7", bar_struct, metadata={"cls": 
fory.get_qualified_classname(Bar)}),
         ],
         metadata={"cls": fory.get_qualified_classname(Foo)},
     )
diff --git a/python/pyfory/tests/test_buffer.py 
b/python/pyfory/tests/test_buffer.py
index 3ba9c388e..cefd6abf5 100644
--- a/python/pyfory/tests/test_buffer.py
+++ b/python/pyfory/tests/test_buffer.py
@@ -217,10 +217,7 @@ def check_varuint64(buf: Buffer, value: int, 
bytes_written: int):
     assert buf.writer_index == buf.reader_index
     assert value == varint
     # test slow read branch in `read_varint64`
-    assert (
-        buf.slice(reader_index, buf.reader_index - 
reader_index).read_varuint64()
-        == value
-    )
+    assert buf.slice(reader_index, buf.reader_index - 
reader_index).read_varuint64() == value
 
 
 def test_write_buffer():
diff --git a/python/pyfory/tests/test_codegen.py 
b/python/pyfory/tests/test_codegen.py
index 3b2243b29..b73d2465e 100644
--- a/python/pyfory/tests/test_codegen.py
+++ b/python/pyfory/tests/test_codegen.py
@@ -43,8 +43,6 @@ def test_debug_compiled():
 
 
 def test_compile_function():
-    code, func = codegen.compile_function(
-        "test_compile_function", ["x"], ["print(1)", "print(2)", "return x"], 
{}
-    )
+    code, func = codegen.compile_function("test_compile_function", ["x"], 
["print(1)", "print(2)", "return x"], {})
     print(code)
     assert func(100) == 100
diff --git a/python/pyfory/tests/test_metastring.py 
b/python/pyfory/tests/test_metastring.py
index f21e09585..d470de299 100644
--- a/python/pyfory/tests/test_metastring.py
+++ b/python/pyfory/tests/test_metastring.py
@@ -196,7 +196,5 @@ def test_non_ascii_encoding_and_non_utf8():
 
     non_ascii_string = "こんにちは"  # Non-ASCII string
 
-    with pytest.raises(
-        ValueError, match="Unsupported character for LOWER_SPECIAL encoding: こ"
-    ):
+    with pytest.raises(ValueError, match="Unsupported character for 
LOWER_SPECIAL encoding: こ"):
         encoder.encode_with_encoding(non_ascii_string, Encoding.LOWER_SPECIAL)
diff --git a/python/pyfory/tests/test_serializer.py 
b/python/pyfory/tests/test_serializer.py
index 6ba56c865..6e5f1cfe2 100644
--- a/python/pyfory/tests/test_serializer.py
+++ b/python/pyfory/tests/test_serializer.py
@@ -18,7 +18,6 @@
 import array
 import datetime
 import gc
-import io
 import os
 import pickle
 import weakref
diff --git a/python/pyfory/type.py b/python/pyfory/type.py
index add96c783..2c2daae64 100644
--- a/python/pyfory/type.py
+++ b/python/pyfory/type.py
@@ -386,30 +386,18 @@ class TypeVisitor(ABC):
 def infer_field(field_name, type_, visitor: TypeVisitor, types_path=None):
     types_path = list(types_path or [])
     types_path.append(type_)
-    origin = (
-        typing.get_origin(type_)
-        if hasattr(typing, "get_origin")
-        else getattr(type_, "__origin__", type_)
-    )
+    origin = typing.get_origin(type_) if hasattr(typing, "get_origin") else 
getattr(type_, "__origin__", type_)
     origin = origin or type_
-    args = (
-        typing.get_args(type_)
-        if hasattr(typing, "get_args")
-        else getattr(type_, "__args__", ())
-    )
+    args = typing.get_args(type_) if hasattr(typing, "get_args") else 
getattr(type_, "__args__", ())
     if args:
         if origin is list or origin == typing.List:
             elem_type = args[0]
             return visitor.visit_list(field_name, elem_type, 
types_path=types_path)
         elif origin is dict or origin == typing.Dict:
             key_type, value_type = args
-            return visitor.visit_dict(
-                field_name, key_type, value_type, types_path=types_path
-            )
+            return visitor.visit_dict(field_name, key_type, value_type, 
types_path=types_path)
         else:
-            raise TypeError(
-                f"Collection types should be {list, dict} instead of {type_}"
-            )
+            raise TypeError(f"Collection types should be {list, dict} instead 
of {type_}")
     else:
         if is_function(origin) or not hasattr(origin, "__annotations__"):
             return visitor.visit_other(field_name, type_, 
types_path=types_path)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to