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

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


The following commit(s) were added to refs/heads/main by this push:
     new 2d7154f12 chore(python): rename numeric typehint (#2808)
2d7154f12 is described below

commit 2d7154f12a7851860e3e194e070d072dd868f97e
Author: Shawn Yang <[email protected]>
AuthorDate: Wed Oct 22 18:09:57 2025 +0800

    chore(python): rename numeric typehint (#2808)
    
    ## Why?
    
    <!-- Describe the purpose of this PR. -->
    
    ## What does this PR do?
    
    rename numeric typehint for the following reasons:
    
      1. Pythonic: Matches Python's built-in type naming conventions
    2. Industry standard: Libraries like NumPy, PyArrow use this style
    (np.int8, pa.int64())
    3. Cleaner type hints: value: int8 is more readable than value: Int8Type
      4. Less redundant: The context already makes it clear these are types
    
    ## Related issues
    
    <!--
    Is there any related issue? If this PR closes them you say say
    fix/closes:
    
    - #xxxx0
    - #xxxx1
    - Fixes #xxxx2
    -->
    
    ## Does this PR introduce any user-facing change?
    
    <!--
    If any user-facing interface changes, please [open an
    issue](https://github.com/apache/fory/issues/new/choose) describing the
    need to do so and update the document if necessary.
    
    Delete section if not applicable.
    -->
    
    - [ ] Does this PR introduce any public API change?
    - [ ] Does this PR introduce any binary protocol compatibility change?
    
    ## Benchmark
    
    <!--
    When the PR has an impact on performance (if you don't know whether the
    PR will have an impact on performance, you can submit the PR first, and
    if it will have impact on performance, the code reviewer will explain
    it), be sure to attach a benchmark data here.
    
    Delete section if not applicable.
    -->
---
 python/README.md                           |  2 +-
 python/pyfory/__init__.py                  | 12 ++++----
 python/pyfory/_registry.py                 | 24 +++++++--------
 python/pyfory/_struct.py                   | 24 +++++++--------
 python/pyfory/tests/test_cross_language.py | 48 +++++++++++++++---------------
 python/pyfory/tests/test_meta_share.py     | 12 ++++----
 python/pyfory/tests/test_struct.py         | 40 ++++++++++++-------------
 python/pyfory/type.py                      | 24 +++++++--------
 8 files changed, 93 insertions(+), 93 deletions(-)

diff --git a/python/README.md b/python/README.md
index db50ba40a..f0bd62a32 100644
--- a/python/README.md
+++ b/python/README.md
@@ -462,7 +462,7 @@ f = pyfory.Fory(xlang=True, ref=True)
 @dataclass
 class Person:
     name: str
-    age: pyfory.Int32Type
+    age: pyfory.int32
 
 f.register(Person, typename="example.Person")
 
diff --git a/python/pyfory/__init__.py b/python/pyfory/__init__.py
index 2abeda2a7..bf070bea4 100644
--- a/python/pyfory/__init__.py
+++ b/python/pyfory/__init__.py
@@ -40,12 +40,12 @@ from pyfory.type import (  # noqa: F401 # pylint: 
disable=unused-import
     record_class_factory,
     get_qualified_classname,
     TypeId,
-    Int8Type,
-    Int16Type,
-    Int32Type,
-    Int64Type,
-    Float32Type,
-    Float64Type,
+    int8,
+    int16,
+    int32,
+    int64,
+    float32,
+    float64,
     # Int8ArrayType,
     Int16ArrayType,
     Int32ArrayType,
diff --git a/python/pyfory/_registry.py b/python/pyfory/_registry.py
index 5cbf09c06..8a0d7d805 100644
--- a/python/pyfory/_registry.py
+++ b/python/pyfory/_registry.py
@@ -72,12 +72,12 @@ from pyfory.meta.metastring import MetaStringEncoder, 
MetaStringDecoder
 from pyfory.meta.meta_compressor import DeflaterMetaCompressor
 from pyfory.type import (
     TypeId,
-    Int8Type,
-    Int16Type,
-    Int32Type,
-    Int64Type,
-    Float32Type,
-    Float64Type,
+    int8,
+    int16,
+    int32,
+    int64,
+    float32,
+    float64,
     load_class,
     is_struct_type,
     record_class_factory,
@@ -256,18 +256,18 @@ class TypeResolver:
         register = functools.partial(self._register_type, internal=True)
         register(None, type_id=TypeId.NA, serializer=NoneSerializer)
         register(bool, type_id=TypeId.BOOL, serializer=BooleanSerializer)
-        register(Int8Type, type_id=TypeId.INT8, serializer=ByteSerializer)
-        register(Int16Type, type_id=TypeId.INT16, serializer=Int16Serializer)
-        register(Int32Type, type_id=TypeId.INT32, serializer=Int32Serializer)
-        register(Int64Type, type_id=TypeId.INT64, serializer=Int64Serializer)
+        register(int8, type_id=TypeId.INT8, serializer=ByteSerializer)
+        register(int16, type_id=TypeId.INT16, serializer=Int16Serializer)
+        register(int32, type_id=TypeId.INT32, serializer=Int32Serializer)
+        register(int64, type_id=TypeId.INT64, serializer=Int64Serializer)
         register(int, type_id=TypeId.INT64, serializer=Int64Serializer)
         register(
-            Float32Type,
+            float32,
             type_id=TypeId.FLOAT32,
             serializer=Float32Serializer,
         )
         register(
-            Float64Type,
+            float64,
             type_id=TypeId.FLOAT64,
             serializer=Float64Serializer,
         )
diff --git a/python/pyfory/_struct.py b/python/pyfory/_struct.py
index 31755f587..d31fe5bb5 100644
--- a/python/pyfory/_struct.py
+++ b/python/pyfory/_struct.py
@@ -26,12 +26,12 @@ from pyfory.type import (
     TypeVisitor,
     infer_field,
     TypeId,
-    Int8Type,
-    Int16Type,
-    Int32Type,
-    Int64Type,
-    Float32Type,
-    Float64Type,
+    int8,
+    int16,
+    int32,
+    int64,
+    float32,
+    float64,
     is_py_array_type,
     is_primitive_type,
 )
@@ -81,12 +81,12 @@ def _to_snow_case(name: str) -> str:
 
 basic_types = {
     bool,
-    Int8Type,
-    Int16Type,
-    Int32Type,
-    Int64Type,
-    Float32Type,
-    Float64Type,
+    int8,
+    int16,
+    int32,
+    int64,
+    float32,
+    float64,
     int,
     float,
     str,
diff --git a/python/pyfory/tests/test_cross_language.py 
b/python/pyfory/tests/test_cross_language.py
index 99fdc3bf7..91e64ab2c 100644
--- a/python/pyfory/tests/test_cross_language.py
+++ b/python/pyfory/tests/test_cross_language.py
@@ -429,21 +429,21 @@ class ComplexObject1:
     f1: Any = None
     f2: str = None
     f3: List[str] = None
-    f4: Dict[pyfory.Int8Type, pyfory.Int32Type] = None
-    f5: pyfory.Int8Type = None
-    f6: pyfory.Int16Type = None
-    f7: pyfory.Int32Type = None
-    f8: pyfory.Int64Type = None
-    f9: pyfory.Float32Type = None
-    f10: pyfory.Float64Type = None
+    f4: Dict[pyfory.int8, pyfory.int32] = None
+    f5: pyfory.int8 = None
+    f6: pyfory.int16 = None
+    f7: pyfory.int32 = None
+    f8: pyfory.int64 = None
+    f9: pyfory.float32 = None
+    f10: pyfory.float64 = None
     f11: pyfory.Int16ArrayType = None
-    f12: List[pyfory.Int16Type] = None
+    f12: List[pyfory.int16] = None
 
 
 @dataclass
 class ComplexObject2:
     f1: Any
-    f2: Dict[pyfory.Int8Type, pyfory.Int32Type]
+    f2: Dict[pyfory.int8, pyfory.int32]
 
 
 def test_serialize_simple_struct_local():
@@ -701,7 +701,7 @@ def test_cross_language_meta_share(data_file_path):
     @dataclass
     class ComplexObject2:
         f1: Any
-        f2: Dict[pyfory.Int8Type, pyfory.Int32Type]
+        f2: Dict[pyfory.int8, pyfory.int32]
 
     fory.register_type(ComplexObject2, namespace="test", 
typename="ComplexObject2")
 
@@ -740,22 +740,22 @@ def 
test_cross_language_meta_share_complex(data_file_path):
     @dataclass
     class ComplexObject2:
         f1: Any
-        f2: Dict[pyfory.Int8Type, pyfory.Int32Type]
+        f2: Dict[pyfory.int8, pyfory.int32]
 
     @dataclass
     class ComplexObject1:
         f1: Any
         f2: str
         f3: List[str]
-        f4: Dict[pyfory.Int8Type, pyfory.Int32Type]
-        f5: pyfory.Int8Type
-        f6: pyfory.Int16Type
-        f7: pyfory.Int32Type
-        f8: pyfory.Int64Type
-        f9: pyfory.Float32Type
-        f10: pyfory.Float64Type
+        f4: Dict[pyfory.int8, pyfory.int32]
+        f5: pyfory.int8
+        f6: pyfory.int16
+        f7: pyfory.int32
+        f8: pyfory.int64
+        f9: pyfory.float32
+        f10: pyfory.float64
         f11: pyfory.Int16ArrayType
-        f12: List[pyfory.Int16Type]
+        f12: List[pyfory.int16]
 
     fory.register_type(ComplexObject1, namespace="test", 
typename="ComplexObject1")
     fory.register_type(ComplexObject2, namespace="test", 
typename="ComplexObject2")
@@ -798,7 +798,7 @@ def test_schema_evolution(data_file_path):
     @dataclass
     class CompatTestV1:
         name: str
-        age: pyfory.Int32Type  # Use specific fory type to match Java Integer
+        age: pyfory.int32  # Use specific fory type to match Java Integer
 
     fory.register_type(CompatTestV1, namespace="test", typename="CompatTest")
 
@@ -838,7 +838,7 @@ def test_backward_compatibility(data_file_path):
     @dataclass
     class CompatTestV1:
         name: str
-        age: pyfory.Int32Type
+        age: pyfory.int32
 
     fory.register_type(CompatTestV1, namespace="test", typename="CompatTest")
 
@@ -873,7 +873,7 @@ def test_field_reordering_compatibility(data_file_path):
     # Version 3 class with reordered fields matching Java CompatTestV3
     @dataclass
     class CompatTestV3:
-        age: pyfory.Int32Type  # Reordered (was second in V1)
+        age: pyfory.int32  # Reordered (was second in V1)
         name: str  # Reordered (was first in V1)
         email: str
         active: bool  # New field
@@ -912,12 +912,12 @@ def test_cross_version_compatibility(data_file_path):
     @dataclass
     class CompatTestV1:
         name: str
-        age: pyfory.Int32Type
+        age: pyfory.int32
 
     @dataclass
     class CompatTestV2:
         name: str
-        age: pyfory.Int32Type
+        age: pyfory.int32
         email: str = "[email protected]"
 
     @dataclass
diff --git a/python/pyfory/tests/test_meta_share.py 
b/python/pyfory/tests/test_meta_share.py
index 024a6262c..7e2c9630c 100644
--- a/python/pyfory/tests/test_meta_share.py
+++ b/python/pyfory/tests/test_meta_share.py
@@ -64,29 +64,29 @@ class NestedStructClassInconsistent:
 @dataclasses.dataclass
 class ListFieldsClass:
     name: str
-    int_list: List[pyfory.Int32Type]
+    int_list: List[pyfory.int32]
     str_list: List[str]
 
 
 @dataclasses.dataclass
 class ListFieldsClassInconsistent:
     name: str
-    int_list: List[str]  # Changed from Int32Type to str
-    str_list: List[pyfory.Int32Type]  # Changed from str to Int32Type
+    int_list: List[str]  # Changed from int32 to str
+    str_list: List[pyfory.int32]  # Changed from str to int32
 
 
 @dataclasses.dataclass
 class DictFieldsClass:
     name: str
-    int_dict: Dict[str, pyfory.Int32Type]
+    int_dict: Dict[str, pyfory.int32]
     str_dict: Dict[str, str]
 
 
 @dataclasses.dataclass
 class DictFieldsClassInconsistent:
     name: str
-    int_dict: Dict[str, str]  # Changed from Int32Type to str
-    str_dict: Dict[str, pyfory.Int32Type]  # Changed from str to Int32Type
+    int_dict: Dict[str, str]  # Changed from int32 to str
+    str_dict: Dict[str, pyfory.int32]  # Changed from str to int32
 
 
 class TestMetaShareMode:
diff --git a/python/pyfory/tests/test_struct.py 
b/python/pyfory/tests/test_struct.py
index 093f8396b..f114b3917 100644
--- a/python/pyfory/tests/test_struct.py
+++ b/python/pyfory/tests/test_struct.py
@@ -36,21 +36,21 @@ def ser_de(fory, obj):
 
 @dataclass
 class SimpleObject:
-    f1: Dict[pyfory.Int32Type, pyfory.Float64Type] = None
+    f1: Dict[pyfory.int32, pyfory.float64] = None
 
 
 @dataclass
 class ComplexObject:
     f1: Any = None
     f2: Any = None
-    f3: pyfory.Int8Type = 0
-    f4: pyfory.Int16Type = 0
-    f5: pyfory.Int32Type = 0
-    f6: pyfory.Int64Type = 0
-    f7: pyfory.Float32Type = 0
-    f8: pyfory.Float64Type = 0
-    f9: List[pyfory.Int16Type] = None
-    f10: Dict[pyfory.Int32Type, pyfory.Float64Type] = None
+    f3: pyfory.int8 = 0
+    f4: pyfory.int16 = 0
+    f5: pyfory.int32 = 0
+    f6: pyfory.int64 = 0
+    f7: pyfory.float32 = 0
+    f8: pyfory.float64 = 0
+    f9: List[pyfory.int16] = None
+    f10: Dict[pyfory.int32, pyfory.float64] = None
 
 
 def test_struct():
@@ -88,12 +88,12 @@ def test_struct():
 @dataclass
 class SuperClass1:
     f1: Any = None
-    f2: pyfory.Int8Type = 0
+    f2: pyfory.int8 = 0
 
 
 @dataclass
 class ChildClass1(SuperClass1):
-    f3: Dict[str, pyfory.Float64Type] = None
+    f3: Dict[str, pyfory.float64] = None
 
 
 def test_strict():
@@ -141,20 +141,20 @@ class DataClassObject:
 def test_sort_fields():
     @dataclass
     class TestClass:
-        f1: pyfory.Int32Type
-        f2: List[pyfory.Int16Type]
-        f3: Dict[str, pyfory.Float64Type]
+        f1: pyfory.int32
+        f2: List[pyfory.int16]
+        f3: Dict[str, pyfory.float64]
         f4: str
-        f5: pyfory.Float32Type
+        f5: pyfory.float32
         f6: bytes
         f7: bool
         f8: Any
-        f9: Dict[pyfory.Int32Type, pyfory.Float64Type]
+        f9: Dict[pyfory.int32, pyfory.float64]
         f10: List[str]
-        f11: pyfory.Int8Type
-        f12: pyfory.Int64Type
-        f13: pyfory.Float64Type
-        f14: Set[pyfory.Int32Type]
+        f11: pyfory.int8
+        f12: pyfory.int64
+        f13: pyfory.float64
+        f14: Set[pyfory.int32]
         f15: datetime.datetime
 
     fory = Fory(xlang=True, ref=True)
diff --git a/python/pyfory/type.py b/python/pyfory/type.py
index f41c7841d..9f766dfd2 100644
--- a/python/pyfory/type.py
+++ b/python/pyfory/type.py
@@ -232,22 +232,22 @@ __NAMESPACED_TYPES__ = {
     TypeId.NAMED_STRUCT,
     TypeId.NAMED_COMPATIBLE_STRUCT,
 }
-Int8Type = TypeVar("Int8Type", bound=int)
-Int16Type = TypeVar("Int16Type", bound=int)
-Int32Type = TypeVar("Int32Type", bound=int)
-Int64Type = TypeVar("Int64Type", bound=int)
-Float32Type = TypeVar("Float32Type", bound=float)
-Float64Type = TypeVar("Float64Type", bound=float)
+int8 = TypeVar("int8", bound=int)
+int16 = TypeVar("int16", bound=int)
+int32 = TypeVar("int32", bound=int)
+int64 = TypeVar("int64", bound=int)
+float32 = TypeVar("float32", bound=float)
+float64 = TypeVar("float64", bound=float)
 
 _primitive_types = {
     int,
     float,
-    Int8Type,
-    Int16Type,
-    Int32Type,
-    Int64Type,
-    Float32Type,
-    Float64Type,
+    int8,
+    int16,
+    int32,
+    int64,
+    float32,
+    float64,
 }
 
 _primitive_types_ids = {


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

Reply via email to