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 0bfe7b290 fix(python): register dynamic serializer only not require
registration (#2634)
0bfe7b290 is described below
commit 0bfe7b2909eadc3a8b37d6dda6d42ac25a82a185
Author: Shawn Yang <[email protected]>
AuthorDate: Sat Sep 20 01:49:29 2025 +0800
fix(python): register dynamic serializer only not require registration
(#2634)
<!--
**Thanks for contributing to Apache Fory™.**
**If this is your first time opening a PR on fory, you can refer to
[CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).**
Contribution Checklist
- The **Apache Fory™** community has requirements on the naming of pr
titles. You can also find instructions in
[CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).
- Apache Fory™ has a strong focus on performance. If the PR you submit
will have an impact on performance, please benchmark it first and
provide the benchmark result here.
-->
## Why?
<!-- Describe the purpose of this PR. -->
## What does this PR do?
<!-- Describe the details of this PR. -->
## Related issues
#2629
## 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/pyfory/_registry.py | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)
diff --git a/python/pyfory/_registry.py b/python/pyfory/_registry.py
index 8a8af306f..b1a714417 100644
--- a/python/pyfory/_registry.py
+++ b/python/pyfory/_registry.py
@@ -216,14 +216,16 @@ class TypeResolver:
register(slice, serializer=SliceSerializer)
register(np.ndarray, serializer=NDArraySerializer)
register(array.array, serializer=DynamicPyArraySerializer)
- self._internal_py_serializer_map = {
- ReduceSerializer: (self._stub_cls("__Reduce__"),
self._next_type_id()),
- TypeSerializer: (self._stub_cls("__Type__"), self._next_type_id()),
- MethodSerializer: (self._stub_cls("__Method__"),
self._next_type_id()),
- NativeFuncMethodSerializer: (self._stub_cls("__NativeFunction__"),
self._next_type_id()),
- }
- for serializer, (stub_cls, type_id) in
self._internal_py_serializer_map.items():
- register(stub_cls, serializer=serializer, type_id=type_id)
+ if not self.require_registration:
+ self._internal_py_serializer_map = {
+ ReduceSerializer: (self._stub_cls("__Reduce__"),
self._next_type_id()),
+ TypeSerializer: (self._stub_cls("__Type__"),
self._next_type_id()),
+ MethodSerializer: (self._stub_cls("__Method__"),
self._next_type_id()),
+ FunctionSerializer: (self._stub_cls("__Function__"),
self._next_type_id()),
+ NativeFuncMethodSerializer:
(self._stub_cls("__NativeFunction__"), self._next_type_id()),
+ }
+ for serializer, (stub_cls, type_id) in
self._internal_py_serializer_map.items():
+ register(stub_cls, serializer=serializer, type_id=type_id)
@staticmethod
def _stub_cls(name: str):
@@ -371,10 +373,6 @@ class TypeResolver:
if issubclass(cls, enum.Enum):
serializer = EnumSerializer(self.fory, cls)
type_id = TypeId.NAMED_ENUM if type_id is None else ((type_id
<< 8) + TypeId.ENUM)
- elif cls is types.FunctionType:
- # Use FunctionSerializer for function types (including lambdas)
- serializer = FunctionSerializer(self.fory, cls)
- type_id = TypeId.NAMED_EXT if type_id is None else ((type_id
<< 8) + TypeId.EXT)
else:
serializer = None
if self.meta_share:
@@ -497,7 +495,7 @@ class TypeResolver:
return type_info
elif not create:
return None
- if self.language != Language.PYTHON or (self.require_registration and
not issubclass(cls, Enum)):
+ if self.require_registration and not issubclass(cls, Enum):
raise TypeUnregisteredError(f"{cls} not registered")
logger.info("Type %s not registered", cls)
serializer = self._create_serializer(cls)
@@ -505,8 +503,6 @@ class TypeResolver:
if self.language == Language.PYTHON:
if isinstance(serializer, EnumSerializer):
type_id = TypeId.NAMED_ENUM
- elif isinstance(serializer, FunctionSerializer):
- type_id = TypeId.NAMED_EXT
elif isinstance(serializer, (ObjectSerializer,
StatefulSerializer)):
type_id = TypeId.NAMED_EXT
elif self._internal_py_serializer_map.get(type(serializer)) is not
None:
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]