@@ -36,7 +36,7 @@ def data_received(self, data):
36
36
_ , payload = request_message .split ('\r \n \r \n ' , 1 )
37
37
task = create_task (self .json_rpc_manager .get_payload_for_payload (payload ))
38
38
task .add_done_callback (self .handle_task_result )
39
-
39
+
40
40
def handle_task_result (self , task ):
41
41
res = task .result ()
42
42
self .transport .write ((
@@ -49,6 +49,12 @@ def handle_task_result(self, task):
49
49
logger .info ('Close the client socket' )
50
50
self .transport .close ()
51
51
52
+ # Compatible with cyfunction.
53
+ # This change helps to work with some modules like `pydantic`, which wraps
54
+ # functions (includes coroutine functions) into cyfunctions. The method
55
+ # `inspect.isfunction()` cannot recognize them for now.
56
+ def is_func_or_cyfunc (object ):
57
+ return isfunction (object ) or (type (object ).__name__ == "cython_function_or_method" )
52
58
53
59
def main ():
54
60
"""Usage: % examples.methods"""
@@ -68,7 +74,7 @@ def main():
68
74
module = importlib .util .module_from_spec (spec )
69
75
spec .loader .exec_module (module )
70
76
# get functions from the module
71
- methods = getmembers (module , isfunction )
77
+ methods = getmembers (module , is_func_or_cyfunc )
72
78
logger .info ('Extracted methods: {}' .format (methods ))
73
79
dispatcher = Dispatcher (dict (methods ))
74
80
0 commit comments