We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
FromPyObject
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In #4829 (comment), FromPyObject was intentionally designed to disallow all fields being set with #[pyo3(default)]. I wonder if this is because:
#[pyo3(default)]
ref: #4829 (comment) the surprising behavior that a variant Foo { #[pyo3(default)] value: usize } becomes a catch-all just like the Foo {} variant.
ref: #4829 (comment)
the surprising behavior that a variant Foo { #[pyo3(default)] value: usize } becomes a catch-all just like the Foo {} variant.
Foo { #[pyo3(default)] value: usize }
Foo {}
However, for me, this behavior makes sense, as I use it to extract class Foo(TypedDict, total=False) for typed kwargs.
class Foo(TypedDict, total=False)
kwargs
// 💥 cannot derive FromPyObject for structs and variants with only default values #[derive(FromPyObject)] #[pyo3(from_item_all)] pub struct Foo { #[pyo3(default)] id: Option<i32>, } #[pyfunction] #[pyo3(signature = (**kwargs))] fn foo(kwargs: Option<&Bound<'_, PyDict>>) -> PyResult<()> { let foo: Option<Foo> = kwargs.map(|kwargs| kwargs.extract::<Foo>()).transpose()?; Ok(()) }
from typing_extensions import NotRequired, TypedDict, Unpack class Foo(TypedDict, total=False): id: NotRequired[int] def foo(**kwargs: Unpack[Foo]) -> None: ... foo() # ok foo(id=1) # ok foo(id=1, foo=2) # Err: no `foo` parameter
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Uh oh!
There was an error while loading. Please reload this page.
In #4829 (comment),
FromPyObject
was intentionally designed to disallow all fields being set with#[pyo3(default)]
. I wonder if this is because:However, for me, this behavior makes sense, as I use it to extract
class Foo(TypedDict, total=False)
for typedkwargs
.The text was updated successfully, but these errors were encountered: