Skip to content

class_schema() vs .Schema #283

@vkruglik-aka

Description

@vkruglik-aka

cc @lovasoa

Can class_schema() and .Schema be used interchangeably on a Marshmallow Dataclass?

The documentation, such as in https://pypi.org/project/marshmallow-dataclass/, suggests to use the class_schema() function to generate a marshmallow Schema class from a python builtin dataclass. The doc doesn't say anything about the use of class_schema() on a Marshmallow Dataclass.

Is there any reason not to use class_schema() on a marshmallow dataclass?

The reason I ask is that .Schema confuses type checkers, and the documentation-suggested addition of Schema: ClassVar[Type[Schema]] = Schema in every marshmallow dataclass to counter this confusion just seems like unnecessary boilerplate, if class_schema() provides the same capability (and it already has the proper type annotations)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions