Maybe this is totally off, but would it even be possible to support arbitrary Python objects? For example, if I had a Python function like this:
class Input(TypedDict):
type: Literal["http"]
status_code: int
method: Literal["GET", "PUT"]
callback: Callable[[], None]
class Output(TypedDict):
message: str
callback: Callable[[], None]
def process(inp: Input) -> Output:
assert inp["type"] == "http"
status_code = input["status_code"]
assert 99 < status_code < 600
method = input["method"]
assert method in ("GET", "PUT")
msg = f'{method} {status_code}"
return Output(message, inp["callback"])
This crate is super convenient to parse and validate type
, status_code
and method
since you can make a declarative serve model for this:
#[derive(Serialize, Deserialize]
#[serde(rename_all = "UPPERCASE")]
enum Method {
Get,
Post,
}
#[derive(Serialize, Deserialize]
struct HTTPMessage {
status_code: u32,
method: Method,
}
#[derive(Serialize, Deserialize]
#[serde(tag = "type")]
enum Message {
Http(HTTPMessage),
}
But as far as I can tell there is no way to say "make the callback
key a Py<PyAny>
. In other words, something like:
#[derive(Serialize, Deserialize]
struct HTTPMessage {
status_code: u32,
method: Method,
callback: Py<PyAny>,
}
Is that right?
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too