Skip to content

Commit ffedbfe

Browse files
committed
Merge branch '3.x-line' into dev
2 parents 9cddff6 + 7a71dfc commit ffedbfe

3 files changed

Lines changed: 45 additions & 8 deletions

File tree

CHANGELOG.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,13 @@ Previously-deprecated APIs have been removed, including:
124124
- ``Field.fail``, which was replaced by ``Field.make_error`` in 3.0.0.
125125
- `json_module` class Meta option (deprecated in 3.0.0b3). Use `render_module` instead.
126126

127-
(unreleased)
128-
************
127+
3.26.1 (2025-02-03)
128+
*******************
129+
130+
Bug fixes:
131+
132+
- Typing: Fix type annotations for `class Meta <marshmallow.Schema.Meta>` options (:issue:`2804`).
133+
Thanks :user:`lawrence-law` for reporting.
129134

130135
Other changes:
131136

src/marshmallow/schema.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,9 @@ class Meta(Schema.Opts):
352352
.. versionremoved:: 4.0.0 Remove ``ordered``.
353353
"""
354354

355-
fields: typing.ClassVar[tuple[Field] | list[Field]]
355+
fields: typing.ClassVar[tuple[str, ...] | list[str]]
356356
"""Fields to include in the (de)serialized result"""
357-
additional: typing.ClassVar[tuple[Field] | list[Field]]
357+
additional: typing.ClassVar[tuple[str, ...] | list[str]]
358358
"""Fields to include in addition to the explicitly declared fields.
359359
`additional <marshmallow.Schema.Meta.additional>` and `fields <marshmallow.Schema.Meta.fields>`
360360
are mutually-exclusive options.
@@ -364,7 +364,7 @@ class Meta(Schema.Opts):
364364
usually better to define fields as class variables, but you may need to
365365
use this option, e.g., if your fields are Python keywords.
366366
"""
367-
exclude: typing.ClassVar[tuple[Field] | list[Field]]
367+
exclude: typing.ClassVar[tuple[str, ...] | list[str]]
368368
"""Fields to exclude in the serialized result.
369369
Nested fields can be represented with dot delimiters.
370370
"""
@@ -376,15 +376,18 @@ class Meta(Schema.Opts):
376376
"""Default format for `DateTime <marshmallow.fields.DateTime>` fields."""
377377
timeformat: typing.ClassVar[str]
378378
"""Default format for `Time <marshmallow.fields.Time>` fields."""
379-
render_module: typing.ClassVar[types.RenderModule]
379+
380+
# FIXME: Use a more constrained type here.
381+
# ClassVar[RenderModule] doesn't work.
382+
render_module: typing.Any
380383
""" Module to use for `loads <marshmallow.Schema.loads>` and `dumps <marshmallow.Schema.dumps>`.
381384
Defaults to `json` from the standard library.
382385
"""
383386
index_errors: typing.ClassVar[bool]
384387
"""If `True`, errors dictionaries will include the index of invalid items in a collection."""
385-
load_only: typing.ClassVar[tuple[Field] | list[Field]]
388+
load_only: typing.ClassVar[tuple[str, ...] | list[str]]
386389
"""Fields to exclude from serialized results"""
387-
dump_only: typing.ClassVar[tuple[Field] | list[Field]]
390+
dump_only: typing.ClassVar[tuple[str, ...] | list[str]]
388391
"""Fields to exclude from serialized results"""
389392
unknown: typing.ClassVar[types.UnknownOption]
390393
"""Whether to exclude, include, or raise an error for unknown fields in the data.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import json
2+
3+
from marshmallow import EXCLUDE, Schema
4+
from marshmallow.fields import Integer, String
5+
6+
7+
# Test that valid `Meta` class attributes pass type checking
8+
class MySchema(Schema):
9+
foo = String()
10+
bar = Integer()
11+
12+
class Meta(Schema.Meta):
13+
fields = ("foo", "bar")
14+
additional = ("baz", "qux")
15+
include = {
16+
"foo2": String(),
17+
}
18+
exclude = ("bar", "baz")
19+
many = True
20+
dateformat = "%Y-%m-%d"
21+
datetimeformat = "%Y-%m-%dT%H:%M:%S"
22+
timeformat = "%H:%M:%S"
23+
render_module = json
24+
ordered = False
25+
index_errors = True
26+
load_only = ("foo", "bar")
27+
dump_only = ("baz", "qux")
28+
unknown = EXCLUDE
29+
register = False

0 commit comments

Comments
 (0)