diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f66ec5715..46d0e7c30 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: - id: pyupgrade args: [--py38-plus] - repo: https://github.com/psf/black - rev: 23.11.0 + rev: 23.12.1 hooks: - id: black language_version: python3 @@ -15,7 +15,7 @@ repos: - id: flake8 additional_dependencies: [flake8-bugbear==23.12.2] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.7.1 + rev: v1.8.0 hooks: - id: mypy additional_dependencies: [types-simplejson, types-pytz, packaging] @@ -25,4 +25,4 @@ repos: rev: 1.16.0 hooks: - id: blacken-docs - additional_dependencies: [black==22.1.0] + additional_dependencies: [black==23.12.1] diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d5911d95c..7f2bb9466 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -395,6 +395,7 @@ Deprecations: from marshmallow import Schema, fields + # <3.3 class PersonSchema(Schema): partner = fields.Nested("self", exclude=("partner",)) diff --git a/docs/custom_fields.rst b/docs/custom_fields.rst index 55c540653..b9110080d 100644 --- a/docs/custom_fields.rst +++ b/docs/custom_fields.rst @@ -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."} ) diff --git a/docs/extending.rst b/docs/extending.rst index d3efe3412..ce736c092 100644 --- a/docs/extending.rst +++ b/docs/extending.rst @@ -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() diff --git a/docs/upgrading.rst b/docs/upgrading.rst index ea7d6f9d2..f697201fd 100644 --- a/docs/upgrading.rst +++ b/docs/upgrading.rst @@ -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() @@ -41,6 +42,7 @@ Passing ``"self"`` is deprecated. from marshmallow import Schema, fields + # <3.3 class PersonSchema(Schema): partner = fields.Nested("self", exclude=("partner",)) @@ -377,6 +379,7 @@ If your `Schema ` overrides `get_attribute ` and `Function ` to add additional data on s from marshmallow import Schema, fields, post_dump + # 2.x class MySchema(Schema): x = fields.Int() @@ -508,6 +513,7 @@ Use a `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() @@ -587,6 +593,7 @@ Subclasses of `SchemaOpts ` receive an additional argume from marshmallow import SchemaOpts + # 2.x class CustomOpts(SchemaOpts): def __init__(self, meta): @@ -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: @@ -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() @@ -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() @@ -899,6 +909,7 @@ The ``Meta`` option ``dateformat`` used to pass format to `DateTime {{'x': '2017-09'}} + # 3.x class MySchema(Schema): x = fields.DateTime() @@ -936,6 +947,7 @@ The ``Meta`` option ``dateformat`` used to pass format to `DateTime {{'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() @@ -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() @@ -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() @@ -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."} @@ -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): @@ -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() @@ -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):