cnzakii commented on code in PR #51:
URL: https://github.com/apache/dubbo-python/pull/51#discussion_r2197300329


##########
src/dubbo/client.py:
##########
@@ -84,68 +86,274 @@ def _initialize(self):
 
     def unary(
         self,
-        method_name: str,
+        interface: Optional[Callable] = None,
+        method_name: Optional[str] = None,
+        params_types: Optional[List[Type]] = None,
+        return_type: Optional[Type] = None,
+        codec: Optional[str] = None,
         request_serializer: Optional[SerializingFunction] = None,
         response_deserializer: Optional[DeserializingFunction] = None,
     ) -> RpcCallable:
-        return self._callable(
-            MethodDescriptor(
-                method_name=method_name,
-                arg_serialization=(request_serializer, None),
-                return_serialization=(None, response_deserializer),
-                rpc_type=RpcTypes.UNARY.value,
+        """
+        Create unary RPC call.
+
+        Supports both automatic mode (via interface) and manual mode (via 
method_name + params_types + return_type + codec).
+        """
+
+        # Validate
+        if interface is None and method_name is None:
+            raise ValueError("Either 'interface' or 'method_name' must be 
provided")
+
+        # Determine the actual method name to call
+        actual_method_name = method_name or (interface.__name__ if interface 
else "unary")
+        
+        # Build method descriptor (automatic or manual)
+        if interface:
+            method_desc = DubboTransportService.create_method_descriptor(
+                func=interface,
+                method_name=actual_method_name,
+                parameter_types=params_types,
+                return_type=return_type,
+                interface=interface,
             )
+        else:
+            # Manual mode fallback: use dummy function for descriptor creation
+            def dummy(): pass
+
+            method_desc = DubboTransportService.create_method_descriptor(
+                func=dummy,
+                method_name=actual_method_name,
+                parameter_types=params_types or [],
+                return_type=return_type or Any,
+            )
+
+        # Determine serializers if not provided
+        if request_serializer and response_deserializer:
+            final_request_serializer = request_serializer
+            final_response_deserializer = response_deserializer
+        else:
+            # Use DubboTransportService to generate serialization functions
+            final_request_serializer, final_response_deserializer = 
DubboTransportService.create_serialization_functions(
+                transport_type=codec or "json",
+                parameter_types=[p.annotation for p in method_desc.parameters],
+                return_type=method_desc.return_parameter.annotation,
+            )
+
+        # Create the proper MethodDescriptor for the RPC call
+        # This should match the structure expected by your RpcCallableFactory
+        rpc_method_descriptor = MethodDescriptor(
+            method_name=actual_method_name,
+            arg_serialization=(final_request_serializer, None),  # 
(serializer, deserializer) for arguments
+            return_serialization=(None, final_response_deserializer),  # 
(serializer, deserializer) for return value
+            rpc_type=RpcTypes.UNARY.value,
         )
 
+        # Create and return the RpcCallable
+        return self._callable(rpc_method_descriptor)
+
     def client_stream(
         self,
-        method_name: str,
+        interface: Optional[Callable] = None,
+        method_name: Optional[str] = None,
+        params_types: Optional[List[Type]] = None,
+        return_type: Optional[Type] = None,
+        codec: Optional[str] = None,
         request_serializer: Optional[SerializingFunction] = None,
         response_deserializer: Optional[DeserializingFunction] = None,
     ) -> RpcCallable:
-        return self._callable(
-            MethodDescriptor(
-                method_name=method_name,
-                arg_serialization=(request_serializer, None),
-                return_serialization=(None, response_deserializer),
-                rpc_type=RpcTypes.CLIENT_STREAM.value,
+        """

Review Comment:
   I also hope to see the implementation on the server side



##########
src/dubbo/codec/json_codec/json_codec_handler.py:
##########
@@ -0,0 +1,322 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from typing import Any, Type, List, Union, Dict, TypeVar, Protocol
+from datetime import datetime, date, time
+from decimal import Decimal
+from pathlib import Path
+from uuid import UUID
+import json
+
+from .json_type import (
+    TypeProviderFactory, SerializationState,
+    SerializationException, DeserializationException
+)
+
+try:
+    import orjson
+    HAS_ORJSON = True
+except ImportError:
+    HAS_ORJSON = False
+
+try:
+    import ujson
+    HAS_UJSON = True
+except ImportError:
+    HAS_UJSON = False
+
+try:
+    from pydantic import BaseModel, create_model
+    HAS_PYDANTIC = True
+except ImportError:
+    HAS_PYDANTIC = False
+
+
+class EncodingFunction(Protocol):
+    def __call__(self, obj: Any) -> bytes: ...
+
+
+class DecodingFunction(Protocol):
+    def __call__(self, data: bytes) -> Any: ...
+
+
+ModelT = TypeVar('ModelT', bound=BaseModel)
+
+
+class CustomJSONEncoder(json.JSONEncoder):

Review Comment:
   Add high-coverage unit tests to validate your code.



##########
src/dubbo/classes.py:
##########
@@ -13,10 +13,12 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
 import abc
 import threading
-from typing import Any, Callable, Optional, Union
-
+from typing import Any, Callable, Optional, Union,Type
+from abc import ABC, abstractmethod
+from pydantic import BaseModel

Review Comment:
   This place will still cause strong dependency on pydantic



##########
src/dubbo/client.py:
##########
@@ -84,68 +86,274 @@ def _initialize(self):
 
     def unary(
         self,
-        method_name: str,
+        interface: Optional[Callable] = None,
+        method_name: Optional[str] = None,
+        params_types: Optional[List[Type]] = None,
+        return_type: Optional[Type] = None,
+        codec: Optional[str] = None,
         request_serializer: Optional[SerializingFunction] = None,
         response_deserializer: Optional[DeserializingFunction] = None,
     ) -> RpcCallable:
-        return self._callable(
-            MethodDescriptor(
-                method_name=method_name,
-                arg_serialization=(request_serializer, None),
-                return_serialization=(None, response_deserializer),
-                rpc_type=RpcTypes.UNARY.value,
+        """
+        Create unary RPC call.
+
+        Supports both automatic mode (via interface) and manual mode (via 
method_name + params_types + return_type + codec).
+        """
+
+        # Validate

Review Comment:
   There are multiple duplicate codes. You can move the related codes to 
`self._callable`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org
For additional commands, e-mail: notifications-h...@dubbo.apache.org

Reply via email to