Skip to content

Support for pyclass(new = "from_fields") #409

@dmelcer9

Description

@dmelcer9

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions