Skip to content

Support programatically added members in "bysource" ordering #299

@coretl

Description

@coretl

Consider an example where we add some fields programmatically (after #121 is fixed):

from pydantic import Field
from pydantic.dataclasses import dataclass

def _add_type_field(cls):
    cls.__annotations__['type'] = str
    cls.type = Field(cls.__name__, description='The type of the class')
    return cls


@dataclass
@_add_type_field
class DataclassWithAddedField:
    """Dataclass with added field"""

    field: str = Field(description='The field')

If we ask autodoc_pydantic to document this class with "bysource" it won't be able to order the "type" field and will fail with ValueError("Field type in DataclassWithAddedField not found in tagorder").

I would prefer the field to be added at the end.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions