marshmallow-code / marshmallow-code/marshmallow

Meta Decorator

Open
#1,879 12 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.2k
Forks
738
Avg merge
1d 23h
Merged PRs (30d)
7

Description

## 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:

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

class Meta:
type_ = 'tests'
ordered = True
```

After:

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing how Schema classes handle their nested Meta class and compare that behavior with the proposed @meta(type_='tests', ordered=True) usage. Confirm how decorator arguments should become Meta attributes, including the marshmallow-jsonapi type_ case. Done means the decorator works for the shown schema pattern and preserves the existing Meta behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.