Skip to content

Commit e694f66

Browse files
committed
add check for number of variables
1 parent b4e5c31 commit e694f66

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/lib.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,28 @@ impl<R: Runtime, T: Manager<R> + Sync> crate::PythonExt<R> for T {
6767
if INIT_BLOCKED.load(std::sync::atomic::Ordering::Relaxed) {
6868
return Err("Cannot register after function called".into());
6969
}
70-
7170
FUNCTION_MAP
7271
.lock()
7372
.unwrap()
7473
.insert(payload.python_function_call.clone());
74+
7575
let _tmp = self
7676
.runner()
7777
.read_variable(&payload.python_function_call)
7878
.await?;
79+
if let Some(num_args) = payload.number_of_args {
80+
let py_analyze_sig = format!(
81+
r#"
82+
from inspect import signature
83+
if len(signature({}).parameters) != {}:
84+
raise Exception("Function parameters don't match in 'registerFunction'")
85+
"#,
86+
&payload.python_function_call, num_args
87+
);
88+
self.runner().run(&py_analyze_sig).await.unwrap_or_else(|_| {
89+
panic!("Number of args doesn't match signature of {}.", payload.python_function_call)
90+
});
91+
};
7992
Ok(StringResponse { value: "Ok".into() })
8093
}
8194

0 commit comments

Comments
 (0)