You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We currently extract all arguments using the FromPyObject trait and often run into conflicts whether this should be strict, i.e. basically only downcasting the Python objects to the Python equivalents of the target Rust types, or loose, i.e. using the most general available Python API to produce an instance the target Rust type even if these are conceptually unrelated. Concrete example as are PyBool/bool and whether this should use only downcasting or the full truth value testing procedure or PySequence/Vec which might check whether the Python type is actually or sequence or take any iterable and collect it into a Rust Vec.
One way to alleviate this issue is to allow the user to choose which strategy to pursue, for example by adding a #[pyo3(noconvert)] argument attribute to explicitly request a strict conversion.
The text was updated successfully, but these errors were encountered:
An alternative I'm wondering about is that we could default to stricter conversions, which feels more Rust-y, and then have #[pyo3(lax)] to allow conversions.
Implementation-wise, I think we could either add this as a defaulted method to the FromPyObject trait or add a new FromPyObjectLax trait. We'd probably figure out which is nicer quite quickly.
We currently extract all arguments using the
FromPyObject
trait and often run into conflicts whether this should be strict, i.e. basically only downcasting the Python objects to the Python equivalents of the target Rust types, or loose, i.e. using the most general available Python API to produce an instance the target Rust type even if these are conceptually unrelated. Concrete example as arePyBool/bool
and whether this should use only downcasting or the full truth value testing procedure orPySequence/Vec
which might check whether the Python type is actually or sequence or take any iterable and collect it into a RustVec
.One way to alleviate this issue is to allow the user to choose which strategy to pursue, for example by adding a
#[pyo3(noconvert)]
argument attribute to explicitly request a strict conversion.The text was updated successfully, but these errors were encountered: