Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 26, 2023
1 parent ff5f5a1 commit be19922
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ Deprecations:
from marshmallow import Schema, fields
# <3.3
class PersonSchema(Schema):
partner = fields.Nested("self", exclude=("partner",))
Expand Down
1 change: 0 additions & 1 deletion docs/custom_fields.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ Error messages can also be passed to a `Field's` constructor.
class UserSchema(Schema):
name = fields.Str(
required=True, error_messages={"required": "Please provide a name."}
)
Expand Down
1 change: 1 addition & 0 deletions docs/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ The pipeline for serialization is similar, except that the ``pass_many=True`` pr
from marshmallow import Schema, fields, pre_load
# YES
class MySchema(Schema):
field_a = fields.Field()
Expand Down
18 changes: 18 additions & 0 deletions docs/upgrading.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Use this to resolve order-of-declaration issues when schemas nest each other.
from marshmallow import Schema, fields
# <3.3
class AlbumSchema(Schema):
title = fields.Str()
Expand Down Expand Up @@ -41,6 +42,7 @@ Passing ``"self"`` is deprecated.
from marshmallow import Schema, fields
# <3.3
class PersonSchema(Schema):
partner = fields.Nested("self", exclude=("partner",))
Expand Down Expand Up @@ -377,6 +379,7 @@ If your `Schema <marshmallow.Schema>` overrides `get_attribute <marshmallow.Sche
from marshmallow import Schema
# 2.x
class MySchema(Schema):
def get_attribute(self, attr, obj, default):
Expand Down Expand Up @@ -458,6 +461,7 @@ The `Method <marshmallow.fields.Method>` and `Function <marshmallow.fields.Funct
from marshmallow import Schema, fields, missing
# 2.x
class ShapeSchema(Schema):
area = fields.Method("get_area")
Expand Down Expand Up @@ -498,6 +502,7 @@ Use a `post_dump <marshmallow.decorators.post_dump>` to add additional data on s
from marshmallow import Schema, fields, post_dump
# 2.x
class MySchema(Schema):
x = fields.Int()
Expand All @@ -508,6 +513,7 @@ Use a `post_dump <marshmallow.decorators.post_dump>` to add additional data on s
schema.dump({"x": 1, "y": 2})
# => {'z': 123, 'y': 2, 'x': 1}
# 3.x
class MySchema(Schema):
x = fields.Int()
Expand Down Expand Up @@ -587,6 +593,7 @@ Subclasses of `SchemaOpts <marshmallow.SchemaOpts>` receive an additional argume
from marshmallow import SchemaOpts
# 2.x
class CustomOpts(SchemaOpts):
def __init__(self, meta):
Expand Down Expand Up @@ -661,6 +668,7 @@ The ``json_module`` class Meta option is deprecated in favor of ``render_module`
import ujson
# 2.x
class MySchema(Schema):
class Meta:
Expand Down Expand Up @@ -737,6 +745,7 @@ This use case is covered by using two different `Schema`.
from marshmallow import Schema, fields
# 2.x
class UserSchema(Schema):
id = fields.Str()
Expand Down Expand Up @@ -867,6 +876,7 @@ In marshmallow 2.x, ``Float`` field would serialize and deserialize special valu
MySchema().load({"x": "nan"})
# => {{'x': nan}}
# 3.x
class MySchema(Schema):
x = fields.Float()
Expand Down Expand Up @@ -899,6 +909,7 @@ The ``Meta`` option ``dateformat`` used to pass format to `DateTime <marshmallow
MySchema().dump({"x": dt.datetime(2017, 9, 19)})
# => {{'x': '2017-09'}}
# 3.x
class MySchema(Schema):
x = fields.DateTime()
Expand Down Expand Up @@ -936,6 +947,7 @@ The ``Meta`` option ``dateformat`` used to pass format to `DateTime <marshmallow
)
# => {{'x': '2017-09-19T00:00:00+00:00', 'y': '2017-09-18T22:00:00+00:00', 'z': '2017-09-19T00:00:00+02:00'}}
# 3.x
class MySchema(Schema):
x = fields.DateTime()
Expand Down Expand Up @@ -967,6 +979,7 @@ The ``prefix`` parameter of ``Schema`` is removed. The same feature can be achie
MySchema(prefix="pre_").dump({"f1": "one", "f2": "two"})
# {'pre_f1': 'one', '_pre_f2': 'two'}
# 3.x
class MySchema(Schema):
f1 = fields.Field()
Expand Down Expand Up @@ -1023,6 +1036,7 @@ In marshmallow 2, it was possible to have multiple fields with the same ``attrib
MySchema()
#  No error
# 3.x
class MySchema(Schema):
f1 = fields.Field()
Expand Down Expand Up @@ -1058,6 +1072,7 @@ re-raise exceptions using ``raise ... from ...``.
from marshmallow import fields, ValidationError
from packaging import version
# 2.x
class Version(fields.Field):
default_error_messages = {"invalid": "Not a valid version."}
Expand Down Expand Up @@ -1101,6 +1116,7 @@ should accept ``**kwargs``:
from marshmallow import fields, ValidationError
from packaging import version
# 2.x
class MyCustomField(fields.Field):
def _deserialize(self, value, attr, obj):
Expand Down Expand Up @@ -1318,6 +1334,7 @@ Custom accessors and error handlers are now defined as methods. `Schema.accessor
from marshmallow import Schema, fields
# 1.0 Deprecated API
class ExampleSchema(Schema):
field_a = fields.Int()
Expand Down Expand Up @@ -1472,6 +1489,7 @@ Two changes must be made to make your custom fields compatible with version 2.0.
from marshmallow import fields, ValidationError
from marshmallow.exceptions import UnmarshallingError
# In 1.0, an UnmarshallingError was raised
class PasswordField(fields.Field):
def _deserialize(self, val):
Expand Down

0 comments on commit be19922

Please sign in to comment.