Skip to content

Commit

Permalink
PyO3: migrate to Bound for src/rust/engine/src/nodes/task.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
tdyas committed Oct 3, 2024
1 parent 5424025 commit 47fb887
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/rust/engine/src/nodes/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use deepsize::DeepSizeOf;
use futures::future::{self, BoxFuture, FutureExt};
use graph::CompoundNode;
use internment::Intern;
use pyo3::prelude::{PyErr, Python};
use pyo3::types::{PyDict, PyTuple};
use pyo3::{IntoPy, PyNativeType, ToPyObject};
use pyo3::prelude::{PyAnyMethods, PyErr, Python};
use pyo3::types::{PyDict, PyDictMethods, PyTuple};
use pyo3::{Bound, IntoPy, ToPyObject};
use rule_graph::DependencyKey;
use workunit_store::{in_workunit, Level, RunningWorkunit};

Expand Down Expand Up @@ -276,13 +276,13 @@ impl Task {
&self.side_effected,
async move {
Python::with_gil(|py| {
let func = (*self.task.func.0.value).as_ref(py);
let func = (*self.task.func.0.value).bind(py);

// If there are explicit positional arguments, apply any computed arguments as
// keywords. Otherwise, apply computed arguments as positional.
let res = if let Some(args) = args {
let args = args.value.extract::<&PyTuple>(py)?;
let kwargs = PyDict::new(py);
let args = args.value.extract::<Bound<'_, PyTuple>>(py)?;
let kwargs = PyDict::new_bound(py);
for ((name, _), value) in self
.task
.args
Expand All @@ -292,9 +292,10 @@ impl Task {
{
kwargs.set_item(name, &value)?;
}
func.call(args, Some(kwargs))
func.call(args, Some(&kwargs))
} else {
let args_tuple = PyTuple::new(py, deps.iter().map(|v| v.to_object(py)));
let args_tuple =
PyTuple::new_bound(py, deps.iter().map(|v| v.to_object(py)));
func.call1(args_tuple)
};

Expand Down

0 comments on commit 47fb887

Please sign in to comment.