Skip to content

Update marshmallow to 4.0.0 #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pyup-bot
Copy link
Collaborator

This PR updates marshmallow from 3.11.1 to 4.0.0.

Changelog

4.0.0

******************

See :ref:`upgrading_4_0` for a guide on updating your code.

Features:

- Typing: Add types to all `Field <marshmallow.fields.Field>` constructor kwargs (:issue:`2285`).
Thanks :user:`navignaw` for the suggestion.
- `DateTime <marshmallow.fields.DateTime>`, `Date <marshmallow.fields.Date>`, `Time <marshmallow.fields.Time>`,
`TimeDelta <marshmallow.fields.TimeDelta>`, and `Enum <marshmallow.fields.Enum>`
accept their internal value types as valid input (:issue:`1415`).
Thanks :user:`bitdancer` for the suggestion.
- `validates <marshmallow.validates>` accepts multiple field names (:issue:`1960`).
*Backwards-incompatible*: Decorated methods now receive ``data_key`` as a keyword argument.
Thanks :user:`dpriskorn` for the suggestion and :user:`dharani7998` for the PR.

Other changes:

- Typing: `Field <marshmallow.fields.Field>` is now a generic type with a type argument for the internal value type.
- `marshmallow.fields.UUID` no longer subclasses `marshmallow.fields.String`.
- *Backwards-incompatible*: Use `datetime.date.fromisoformat`, `datetime.time.fromisoformat`, and `datetime.datetime.fromisoformat` from the standard library to deserialize dates, times and datetimes (:pr:`2078`).
- `marshmallow.Schema.load` no longer silently fails to call schema validators when a generator is passed (:issue:`1898`). 
The typing of `data` is also updated to be more accurate.
Thanks :user:`ziplokk1` for reporting.

As a consequence of this change:
- Time with time offsets are now supported.
- YYYY-MM-DD is now accepted as a datetime and deserialized as naive 00:00 AM.
- `from_iso_date`, `from_iso_time` and `from_iso_datetime` are removed from `marshmallow.utils`.

- Remove `isoformat`, `to_iso_time` and `to_iso_datetime` from `marshmallow.utils` (:pr:`2766`).
- Remove `from_rfc`, and `rfcformat` from `marshmallow.utils` (:pr:`2767`).
- Remove `is_keyed_tuple` from `marshmallow.utils` (:pr:`2768`).
- Remove `get_fixed_timezone` from `marshmallow.utils` (:pr:`2773`).

- *Backwards-incompatible*: `marshmallow.fields.Boolean` no longer serializes non-boolean values (:pr:`2725`).
- *Backwards-incompatible*: Rename ``schema`` parameter to ``parent`` in `marshmallow.fields.Field._bind_to_schema` (:issue:`1360`).
- *Backwards-incompatible*: Rename ``pass_many`` parameter to ``pass_collection`` in pre/post processing methods (:issue:`1369`).
- *Backwards-incompatible*: `marshmallow.fields.TimeDelta` no longer truncates float values when
deserializing (:pr:`2654`). This allows microseconds to be preserved, e.g.

.. code-block:: python

 from marshmallow import fields

 field = fields.TimeDelta()

  Before
 field.deserialize(12.9)
 datetime.timedelta(seconds=12)
  datetime.timedelta(seconds=12)

  After
 field.deserialize(12.9)
  datetime.timedelta(seconds=12, microseconds=900000)

- Improve performance and minimize float precision loss of `marshmallow.fields.TimeDelta` serialization (:pr:`2654`).
- *Backwards-incompatible*: Remove ``serialization_type`` parameter from
`marshmallow.fields.TimeDelta` (:pr:`2654`).

Thanks :user:`ddelange` for the PR.

- *Backwards-incompatible*: Remove `Schema <marshmallow.schema.Schema>`'s ``context`` attribute (deprecated since 3.24.0). Passing a context
should be done using `contextvars.ContextVar` (:issue:`1826`).
marshmallow 4 provides an experimental `Context <marshmallow.experimental.context.Context>`
manager class that can be used to both set and retrieve context.

.. code-block:: python

 import typing

 from marshmallow import Schema, fields
 from marshmallow.experimental.context import Context


 class UserContext(typing.TypedDict):
     suffix: str


 class UserSchema(Schema):
     name_suffixed = fields.Function(
         lambda obj: obj["name"] + Context[UserContext].get()["suffix"]
     )


 with Context[UserContext]({"suffix": "bar"}):
     UserSchema().dump({"name": "foo"})
      {'name_suffixed': 'foobar'}

- Methods decorated with `marshmallow.pre_load`, `marshmallow.post_load`, `marshmallow.validates_schema`,
receive ``unknown`` as a keyword argument (:pr:`1632`).
Thanks :user:`jforand` for the PR.
- *Backwards-incompatible*: Arguments to `decorators <marshmallow.decorators>` are keyword-only arguments.
- *Backwards-incompatible*: Rename ``json_data`` parameter of `marshmallow.Schema.loads` to ``s``
for compatibility with most render module implementations (`json`, ``simplejson``, etc.) (:pr:`2764`).
Also make it a positional-only argument.
- Incorrectly declaring a field using a field class rather than instance
errors at class declaration time (previously happended when the schema was instantiated) (:pr:`2772`).
- Passing invalid values for ``unknown`` will cause an error in type checkers (:pr:`2771`).

Deprecations/Removals:

- *Backwards-incompatible*: Remove implicit field creation, i.e. using the ``fields`` or ``additional`` class Meta options with undeclared fields (:issue:`1356`).
- The `ordered` class Meta option is removed  (:issue:`2146`). Field order is already preserved by default.
Set `Schema.dict_class` to `OrderedDict` to maintain the previous behavior.
- The `marshmallow.base` module is removed (:pr:`2722`).

Previously-deprecated APIs have been removed, including:

- The ``ordered`` `class Meta <marshmallow.Schema.Meta>` option is removed  (:issue:`2146`) (deprecated in 3.26.0).
- *Backwards-incompatible*: `marshmallow.fields.Number` is no longer usable as a field in a schema (deprecated in 3.24.0).
Use `marshmallow.fields.Integer`, `marshmallow.fields.Float`, or `marshmallow.fields.Decimal` instead.
- *Backwards-incompatible*: `marshmallow.fields.Mapping` is no longer usable as a field in a schema (deprecated in 3.24.0).
- *Backwards-incompatible*: Custom validators must raise a `ValidationError <marshmallow.exceptions.ValidationError>` for invalid values (deprecated in 3.24.0).
Returning `False` is no longer supported (:issue:`1775`).
Use `marshmallow.fields.Dict` instead.
- Remove ``__version__``, ``__parsed_version__``, and ``__version_info__`` attributes (deprecated in 3.21.0).
- `default` and `missing` parameters, which were replaced by `dump_default` and `load_default` in 3.13.0 (:pr:`1742`, :pr:`2700`).
- Passing field metadata via keyword arguments (deprecated in 3.10.0). Use the explicit ``metadata=...``
argument instead (:issue:`1350`).
- `marshmallow.utils.pprint` (deprecated in 3.7.0). Use `pprint.pprint` instead.
- Passing `"self"` to `fields.Nested` (deprecated in 3.3.0). Use a callable instead.
- ``Field.fail``, which was replaced by ``Field.make_error`` in 3.0.0.
- `json_module` class Meta option (deprecated in 3.0.0b3). Use `render_module` instead.

3.26.1

*******************

Bug fixes:

- Typing: Fix type annotations for `class Meta <marshmallow.Schema.Meta>` options (:issue:`2804`).
Thanks :user:`lawrence-law` for reporting.

Other changes:

- Remove default value for the ``data`` param of `Nested._deserialize <marshmallow.fields.Nested._deserialize>` (:issue:`2802`).
Thanks :user:`gbenson` for reporting.

3.26.0

*******************

Features:

- Typing: Add type annotations and improved documentation for `class Meta <marshmallow.Schema.Meta>` options (:pr:`2760`).
- Typing: Improve type coverage of `marshmallow.Schema.SchemaMeta` (:pr:`2761`).
- Typing: `marshmallow.Schema.loads` parameter allows `bytes` and `bytesarray` (:pr:`2769`).

Bug fixes:

- Respect ``data_key`` when schema validators raise a `ValidationError <marshmallow.exceptions.ValidationError>` 
with a ``field_name`` argument (:issue:`2170`). Thanks :user:`matejsp` for reporting.
- Correctly handle multiple `post_load <marshmallow.post_load>` methods where one method appends to
the data and another passes ``pass_original=True`` (:issue:`1755`).
Thanks :user:`ghostwheel42` for reporting.
- ``URL`` fields now properly validate ``file`` paths (:issue:`2249`).
Thanks :user:`0xDEC0DE` for reporting and fixing.

Documentation:

- Add :doc:`upgrading guides <upgrading>` for 3.24 and 3.26 (:pr:`2780`).
- Various documentation improvements (:pr:`2757`, :pr:`2759`, :pr:`2765`, :pr:`2774`, :pr:`2778`, :pr:`2783`, :pr:`2796`).

Deprecations:

- The ``ordered`` `class Meta <marshmallow.Schema.Meta>` option is deprecated (:issue:`2146`, :pr:`2762`).
Field order is already preserved by default. Set `marshmallow.Schema.dict_class` to `collections.OrderedDict`
to maintain the previous behavior.

3.25.1

*******************

Bug fixes:

- Typing: Fix type annotations for `Tuple <marshmallow.fields.Tuple>`,
`Boolean <marshmallow.fields.Boolean>`, and `Pluck <marshmallow.fields.Pluck>`
constructors (:pr:`2756`).
- Typing: Fix overload for `marshmallow.class_registry.get_class` (:pr:`2756`).

Documentation:

- Various documentation improvements (:pr:`2746`, :pr:`2747`, :pr:`2748`, :pr:`2749`, :pr:`2750`, :pr:`2751`).

3.25.0

*******************

Features:

- Typing: Improve type annotations for ``SchemaMeta.get_declared_fields`` (:pr:`2742`).

Bug fixes:

- Typing: Relax type annotation for ``Schema.opts`` to allow subclasses to define their own
options classes (:pr:`2744`).

Other changes:

- Restore ``marshmallow.base.SchemaABC`` for backwards-compatibility (:issue:`2743`).
Note that this class is deprecated and will be removed in marshmallow 4.
Use `marshmallow.schema.Schema` as a base class for type-checking instead.

3.24.2

*******************

Changes:

- Don't override ``__new__`` to avoid breaking usages of `inspect.signature` with
`Field <marshmallow.fields.Field>` classes.
This allows marshmallow-sqlalchemy users to upgrade marshmallow without
upgrading to marshmallow-sqlalchemy>=1.1.1.

Documentation:

- Add top-level API back to docs (:issue:`2739`).
Thanks :user:`llucax` for reporting.

3.24.1

*******************

Bug fixes:

- Typing: Fix typing for `class_registry.get_class <marshmallow.class_registry.get_class>` (:pr:`2735`).

3.24.0

*******************

Features:

- Typing: Improve typings in `marshmallow.fields` (:pr:`2723`).
- Typing: Replace type comments with inline typings (:pr:`2718`).

Bug fixes:

- Typing: Fix type hint for ``nested`` parameter of `Nested <marshmallow.fields.Nested>` (:pr:`2721`).

Deprecations:

- Custom validators should raise a `ValidationError <marshmallow.exceptions.ValidationError>` for invalid values.
Returning `False`` is no longer supported .
- Deprecate ``context`` parameter of `Schema <marshmallow.schema.Schema>` (:issue:`1826`).
Use `contextVars.ContextVar` to pass context data instead.
- `Field <marshmallow.fields.Field>`, `Mapping <marshmallow.fields.Mapping>`,
and `Number <marshmallow.fields.Number>` should no longer be used as fields within schemas.
Use their subclasses instead.

3.23.3

*******************

Bug fixes:

- Typing: Fix typing for `Schema.from_dict <marshmallow.schema.Schema.from_dict>` (:issue:`1653`).
Thanks :user:`SteadBytes` for reporting.

Support:

- Documentation: Various documentation cleanups, including more concise docs in the `marshmallow.fields` API reference (:issue:`2307`).
Thanks :user:`AbdealiLoKo` for reporting.

3.23.2

*******************

Bug fixes:

- Improve type hint formatting for ``Field``, ``Nested``, and ``Function`` fields
to resolve PyCharm warnings (:issue:`2268`).
Thanks :user:`Fares-Abubaker` for reporting and fixing.

3.23.1

*******************

Support:

- Document ``absolute`` parameter of ``URL`` field (:pr:`2327`).
- Documentation: Remove (outdated) minimum Python 3 minor version in
documentation and README (:pr:`2323`).

3.23.0

*******************

Features:

- Typing: replace "type" with specific metaclass for ``Schema`` and ``Field``.

Other changes:

- Officially support Python 3.13 (:pr:`2319`).
- Drop support for Python 3.8 (:pr:`2318`).

3.22.0

*******************

Features:

- Add ``many`` Meta option to ``Schema`` so it expects a collection by default (:issue:`2270`).
Thanks :user:`himalczyk` for reporting and :user:`deckar01` for the PR.
- Refactor hooks (:pr:`2279`).
Thanks :user:`deckar01` for the PR.

3.21.3

*******************

Bug fixes:

- Fix memory leak that prevented schema instances from getting GC'd (:pr:`2277`).
Thanks :user:`mrcljx` for the PR.

3.21.2

*******************

Bug fixes:

- Allow timestamp 0 in ``fields.DateTime`` (:issue:`2133`).
Thanks :user:`flydzen` for reporting.

3.21.1

*******************

Bug fixes:

- Fix error message when field is declared as a class and not an instance (:issue:`2245`).
Thanks :user:`travnick` for reporting.

3.21.0

*******************

Bug fixes:

- Fix validation of ``URL`` fields to allow missing user field,
per NWG RFC 3986 (:issue:`2232`). Thanks :user:`ddennerline3` for reporting
and :user:`deckar01` for the PR.

Other changes:

- *Backwards-incompatible*: ``__version__``, ``__parsed_version__``, and ``__version_info__``
attributes are deprecated (:issue:`2227`). Use feature detection or
``importlib.metadata.version("marshmallow")`` instead.

3.20.2

*******************

Bug fixes:

- Fix ``Nested`` field type hint for lambda ``Schema`` types (:pr:`2164`).
Thanks :user:`somethingnew2-0` for the PR.

Other changes:

- Officially support Python 3.12 (:pr:`2188`).
Thanks :user:`hugovk` for the PR.

3.20.1

*******************

Bug fixes:

- Fix call to ``get_declared_fields``: pass ``dict_cls`` again (:issue:`2152`).
Thanks :user:`Cheaterman` for reporting.

3.20.0

*******************

Features:

- Add ``absolute`` parameter to ``URL`` validator and ``Url`` field (:pr:`2123`).
Thanks :user:`sirosen` for the PR.
- Use Abstract Base Classes to define ``FieldABC`` and ``SchemaABC``
(:issue:`1449`). Thanks :user:`aditkumar72` for the PR.
- Use `OrderedSet` as default `set_class`. Schemas are now ordered by default.
(:issue:`1744`)

Bug fixes:

- Handle ``OSError`` and ``OverflowError`` in ``utils.from_timestamp`` (:pr:`2102`).
Thanks :user:`TheBigRoomXXL` for the PR.
- Fix the default inheritance of nested partial schemas (:issue:`2149`).
Thanks :user:`matejsp` for reporting.

Other changes:

- Officially support Python 3.11 (:pr:`2067`).
- Drop support for Python 3.7 (:pr:`2135`).

3.19.0

*******************

Features:

- Add ``timestamp`` and ``timestamp_ms`` formats to ``fields.DateTime``
(:issue:`612`).
Thanks :user:`vgavro` for the suggestion and thanks :user:`vanHoi` for
the PR.

3.18.0

*******************

Features:

- Add ``Enum`` field (:pr:`2017`) and (:pr:`2044`).

Bug fixes:

- Fix typing in ``Field._serialize`` signature (:pr:`2046`).

3.17.1

*******************

Bug fixes:

- Add return type to ``fields.Email.__init__`` (:pr:`2018`).
Thanks :user:`kkirsche` for the PR.
- Add missing type hint to IPInterface __init__ (:pr:`2036`).

3.17.0

*******************

Features:

- Support serialization as float in ``TimeDelta`` field (:pr:`1998`).
Thanks :user:`marcosatti` for the PR.
- Add ``messages_dict`` property to ``ValidationError`` to facilitate type checking
(:pr:`1976`).
Thanks :user:`sirosen` for the PR.

3.16.0

*******************

Features:

- Raise ``ValueError`` if an invalid value is passed to the ``unknown``
argument (:issue:`1721`, :issue:`1732`).
Thanks :user:`sirosen` for the PR.

Other changes:

- Set lower bound for ``packaging`` requirement (:issue:`1957`).
Thanks :user:`MatthewNicolTR` for reporting and thanks :user:`sirosen` for the PR.
- Improve warning messages by passing ``stacklevel`` (:pr:`1986`).
Thanks :user:`tirkarthi` for the PR.

3.15.0

*******************

Features:

- Allow passing a ``dict`` to ``fields.Nested`` (:pr:`1935`).
Thanks :user:`sirosen` for the PR.

Other changes:

- Address distutils deprecation warning in Python 3.10 (:pr:`1903`).
Thanks :user:`kkirsche` for the PR.
- Add py310 to black target-version (:pr:`1921`).
- Drop support for Python 3.6 (:pr:`1923`).
- Use postponed evaluation of annotations (:pr:`1932`).
Thanks :user:`Isira-Seneviratne` for the PR.

3.14.1

*******************

Bug fixes:

- Fix publishing type hints per `PEP-561 <https://www.python.org/dev/peps/pep-0561/>`_
(:pr:`1905`). Thanks :user:`bwindsor` for the catch and patch.

3.14.0

*******************

Bug fixes:

- Fix ``fields.TimeDelta`` serialization precision (:issue:`1865`).
Thanks :user:`yarsanich` for reporting.

Other changes:

- Fix type-hints for ``data`` arg in ``Schema.validate`` to accept
list of dictionaries (:issue:`1790`, :pr:`1868`).
Thanks  :user:`yourun-proger` for PR.
- Improve warning when passing metadata as keyword arguments (:pr:`1882`).
Thanks :user:`traherom` for the PR.
- Don't build universal wheels. We don't support Python 2 anymore.
(:issue:`1860`) Thanks :user:`YKdvd` for reporting.
- Make the build reproducible (:pr:`1862`).
- Drop support for Python 3.5 (:pr:`1863`).
- Test against Python 3.10 (:pr:`1888`).

3.13.0

*******************

Features:

- Replace ``missing``/``default`` field parameters with
``load_default``/``dump_default`` (:pr:`1742`).
Thanks :user:`sirosen` for the PR.

Deprecations:

- The use of ``missing``/``default`` field parameters is deprecated and will be
removed in marshmallow 4. ``load_default``/``dump_default`` should be used
instead.

3.12.2

*******************

Bug fixes:

- Don't expose ``Field``\s as ``Schema`` attributes. This reverts a change
introduced in 3.12.0 that causes issues when field names conflict with
``Schema`` attributes or methods. ``Fields``\s are still accessible on a
``Schema`` instance through the ``fields`` attribute. (:pr:`1843`)

3.12.1

*******************

Bug fixes:

- Fix bug that raised an ``AttributeError`` when instantiating a
``Schema`` with a field named ``parent`` (:issue:`1808`).
Thanks :user:`flying-sheep` for reporting and helping with the fix.

3.12.0

*******************

Features:

- Add ``validate.And`` (:issue:`1768`).
Thanks :user:`rugleb` for the suggestion.
- Add type annotations to ``marshmallow.decorators`` (:issue:`1788`, :pr:`1789`).
Thanks :user:`michaeldimchuk` for the PR.
- Let ``Field``\s be accessed by name as ``Schema`` attributes (:pr:`1631`).

Other changes:

- Improve types in ``marshmallow.validate`` (:pr:`1786`).
- Make ``marshmallow.validate.Validator`` an abstract base class (:pr:`1786`).
- Remove unnecessary list cast (:pr:`1785`).
Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant