Skip to content

Meta Decorator #1879

Open
@deckar01

Description

@deckar01

Motivation

I often have lots of small schemas containing unique Meta classes with only a few attributes. The Meta class sometimes requires more lines than the schema definition and makes a file containing multiple schemas harder to read. This is especially true when using marshmallow-jsonapi due to type_.

Proposal

Provide a meta decorator that will inject its kwargs into a Meta class for the class it is wrapping.

Example

Before:

class TestSchema(Schema):
    foo = fields.String()
    bar = fields.String()

    class Meta:
        type_ = 'tests'
        ordered = True

After:

@meta(type_='tests', ordered=True)
class TestSchema(Schema):
    foo = fields.String()
    bar = fields.String()

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