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
The request is to add a #[pyo3(default)] attribute to allow missing values to be filled in, similar to serde. Note that serde allows Option<T> fields to be missing and fills them with None by default without requiring the attribute; in the linked discussion we agreed that was too implicit for us here.
use pyo3::FromPyObject;#[derive(FromPyObject,Clone)]#[pyo3(from_item_all)]structTest{puba:String,#[pyo3(default)]// <-- this would be the new attributepubb:Option<String>,}#[test]fntest_option() -> Result<()>{Python::with_gil(|py| {let result:Test =
py.eval("{'a': 'test'}",None,None).wrap_err("eval failed")?.extract()?;assert!(result.a == "test");assert!(result.b.is_none());Ok(())})}
The text was updated successfully, but these errors were encountered:
davidhewitt
changed the title
Add #[pyo3(default)] option for `FromPyObject derives
Add #[pyo3(default)] option for FromPyObject derives
Oct 24, 2024
Continuing from #3605
The request is to add a
#[pyo3(default)]
attribute to allow missing values to be filled in, similar to serde. Note thatserde
allowsOption<T>
fields to be missing and fills them withNone
by default without requiring the attribute; in the linked discussion we agreed that was too implicit for us here.The text was updated successfully, but these errors were encountered: