The pyclass macro has an option new="from_fields" that generates a simple default constructor. It seems that pyo3-stub-gen does not pick this up, requiring a manual boilerplate implementation in order to correctly generate type stubs.
Input:
#[gen_stub_pyclass]
#[pyclass(new = "from_fields")]
pub struct Foo {
pub bar: bool,
}
Expected type stub:
@typing.final
class Foo:
def __new__(cls, bar: builtins.bool) -> Foo: ...
Actual:
@typing.final
class Foo:
...
Environment:
rustc 1.94.0 (4a4ef493e 2026-03-02)
pyo3 = "0.28.2"
pyo3-stub-gen = "0.19.0"
The pyclass macro has an option
new="from_fields"that generates a simple default constructor. It seems that pyo3-stub-gen does not pick this up, requiring a manual boilerplate implementation in order to correctly generate type stubs.Input:
Expected type stub:
Actual:
Environment: