Why does this library need to care about types returned by RPC methods? #47
Replies: 1 comment 1 reply
-
Hi Thanks for reaching out. You're basically asking - "why use types at all ?". ;-) As you have a workaround for you need (though I'd encourage you to use better typing to improve the robustness of your code) this is not an issue - I'm converting this to a discussion. <3 Hope you find this information useful. :) |
Beta Was this translation helpful? Give feedback.
-
If you don't put a type annotation on RPC methods, the returned value gets converted to a string:
fastapi_websocket_rpc/fastapi_websocket_rpc/rpc_channel.py
Lines 344 to 346 in 307c149
I don't understand why this is; when serialisation occurs, it's just by asking Pydantic to do whatever it thinks is best:
fastapi_websocket_rpc/fastapi_websocket_rpc/utils.py
Line 77 in 307c149
and deserialisation is even simpler:
fastapi_websocket_rpc/fastapi_websocket_rpc/simplewebsocket.py
Line 41 in 307c149
so I don't see why fastapi_websocket_rpc needs to care about the types in use at all. Am I missing something?
My specific use-case is that I was trying to return a list from an RPC call, and was confused why it was ending up as a string on the other side. Annotating the method with
-> typing.Any
was enough to stop the automatic conversion tostr
.Beta Was this translation helpful? Give feedback.
All reactions