marshmallow 3.23.1__py3-none-any.whl → 3.23.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- marshmallow/fields.py +24 -52
- marshmallow/schema.py +3 -18
- marshmallow/utils.py +1 -1
- {marshmallow-3.23.1.dist-info → marshmallow-3.23.3.dist-info}/METADATA +1 -15
- {marshmallow-3.23.1.dist-info → marshmallow-3.23.3.dist-info}/RECORD +7 -7
- {marshmallow-3.23.1.dist-info → marshmallow-3.23.3.dist-info}/WHEEL +1 -1
- {marshmallow-3.23.1.dist-info → marshmallow-3.23.3.dist-info}/LICENSE +0 -0
marshmallow/fields.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"""Field classes for various types of data."""
|
|
2
|
-
|
|
3
1
|
from __future__ import annotations
|
|
4
2
|
|
|
5
3
|
import collections
|
|
@@ -84,7 +82,6 @@ class Field(FieldABC):
|
|
|
84
82
|
"""Basic field from which other fields should extend. It applies no
|
|
85
83
|
formatting by default, and should only be used in cases where
|
|
86
84
|
data does not need to be formatted before being serialized or deserialized.
|
|
87
|
-
On error, the name of the field will be returned.
|
|
88
85
|
|
|
89
86
|
:param dump_default: If set, this value will be used during serialization if the
|
|
90
87
|
input value is missing. If not set, the field will be excluded from the
|
|
@@ -108,8 +105,9 @@ class Field(FieldABC):
|
|
|
108
105
|
:param required: Raise a :exc:`ValidationError` if the field value
|
|
109
106
|
is not supplied during deserialization.
|
|
110
107
|
:param allow_none: Set this to `True` if `None` should be considered a valid value during
|
|
111
|
-
validation/deserialization. If
|
|
112
|
-
|
|
108
|
+
validation/deserialization. If set to `False` (the default), `None` is considered invalid input.
|
|
109
|
+
If ``load_default`` is explicitly set to `None` and ``allow_none`` is unset,
|
|
110
|
+
`allow_none` is implicitly set to ``True``.
|
|
113
111
|
:param load_only: If `True` skip this field during serialization, otherwise
|
|
114
112
|
its value will be present in the serialized data.
|
|
115
113
|
:param dump_only: If `True` skip this field during deserialization, otherwise
|
|
@@ -118,28 +116,12 @@ class Field(FieldABC):
|
|
|
118
116
|
:param dict error_messages: Overrides for `Field.default_error_messages`.
|
|
119
117
|
:param metadata: Extra information to be stored as field metadata.
|
|
120
118
|
|
|
121
|
-
.. versionchanged:: 2.0.0
|
|
122
|
-
Removed `error` parameter. Use ``error_messages`` instead.
|
|
123
|
-
|
|
124
|
-
.. versionchanged:: 2.0.0
|
|
125
|
-
Added `allow_none` parameter, which makes validation/deserialization of `None`
|
|
126
|
-
consistent across fields.
|
|
127
|
-
|
|
128
|
-
.. versionchanged:: 2.0.0
|
|
129
|
-
Added `load_only` and `dump_only` parameters, which allow field skipping
|
|
130
|
-
during the (de)serialization process.
|
|
131
|
-
|
|
132
|
-
.. versionchanged:: 2.0.0
|
|
133
|
-
Added `missing` parameter, which indicates the value for a field if the field
|
|
134
|
-
is not found during deserialization.
|
|
135
|
-
|
|
136
|
-
.. versionchanged:: 2.0.0
|
|
137
|
-
``default`` value is only used if explicitly set. Otherwise, missing values
|
|
138
|
-
inputs are excluded from serialized output.
|
|
139
|
-
|
|
140
119
|
.. versionchanged:: 3.0.0b8
|
|
141
120
|
Add ``data_key`` parameter for the specifying the key in the input and
|
|
142
121
|
output data. This parameter replaced both ``load_from`` and ``dump_to``.
|
|
122
|
+
|
|
123
|
+
.. versionchanged:: 3.13.0
|
|
124
|
+
Replace ``missing`` and ``default`` parameters with ``load_default`` and ``dump_default``.
|
|
143
125
|
"""
|
|
144
126
|
|
|
145
127
|
# Some fields, such as Method fields and Function fields, are not expected
|
|
@@ -166,9 +148,9 @@ class Field(FieldABC):
|
|
|
166
148
|
data_key: str | None = None,
|
|
167
149
|
attribute: str | None = None,
|
|
168
150
|
validate: (
|
|
169
|
-
|
|
170
|
-
| typing.Callable[[typing.Any], typing.Any]
|
|
151
|
+
typing.Callable[[typing.Any], typing.Any]
|
|
171
152
|
| typing.Iterable[typing.Callable[[typing.Any], typing.Any]]
|
|
153
|
+
| None
|
|
172
154
|
) = None,
|
|
173
155
|
required: bool = False,
|
|
174
156
|
allow_none: bool | None = None,
|
|
@@ -321,8 +303,9 @@ class Field(FieldABC):
|
|
|
321
303
|
self,
|
|
322
304
|
attr: str,
|
|
323
305
|
obj: typing.Any,
|
|
324
|
-
accessor:
|
|
325
|
-
|
|
306
|
+
accessor: (
|
|
307
|
+
typing.Callable[[typing.Any, str, typing.Any], typing.Any] | None
|
|
308
|
+
) = None,
|
|
326
309
|
**kwargs,
|
|
327
310
|
):
|
|
328
311
|
"""Pulls the value for the given key from the object, applies the
|
|
@@ -425,9 +408,6 @@ class Field(FieldABC):
|
|
|
425
408
|
:raise ValidationError: In case of formatting or validation failure.
|
|
426
409
|
:return: The deserialized value.
|
|
427
410
|
|
|
428
|
-
.. versionchanged:: 2.0.0
|
|
429
|
-
Added ``attr`` and ``data`` parameters.
|
|
430
|
-
|
|
431
411
|
.. versionchanged:: 3.0.0
|
|
432
412
|
Added ``**kwargs`` to signature.
|
|
433
413
|
"""
|
|
@@ -538,11 +518,15 @@ class Nested(Field):
|
|
|
538
518
|
|
|
539
519
|
def __init__(
|
|
540
520
|
self,
|
|
541
|
-
nested:
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
521
|
+
nested: (
|
|
522
|
+
SchemaABC
|
|
523
|
+
| SchemaMeta
|
|
524
|
+
| str
|
|
525
|
+
| dict[str, Field | type[Field]]
|
|
526
|
+
| typing.Callable[
|
|
527
|
+
[], SchemaABC | SchemaMeta | dict[str, Field | type[Field]]
|
|
528
|
+
]
|
|
529
|
+
),
|
|
546
530
|
*,
|
|
547
531
|
dump_default: typing.Any = missing_,
|
|
548
532
|
default: typing.Any = missing_,
|
|
@@ -744,10 +728,6 @@ class List(Field):
|
|
|
744
728
|
:param cls_or_instance: A field class or instance.
|
|
745
729
|
:param kwargs: The same keyword arguments that :class:`Field` receives.
|
|
746
730
|
|
|
747
|
-
.. versionchanged:: 2.0.0
|
|
748
|
-
The ``allow_none`` parameter now applies to deserialization and
|
|
749
|
-
has the same semantics as the other fields.
|
|
750
|
-
|
|
751
731
|
.. versionchanged:: 3.0.0rc9
|
|
752
732
|
Does not serialize scalar values to single-item lists.
|
|
753
733
|
"""
|
|
@@ -1459,9 +1439,6 @@ class TimeDelta(Field):
|
|
|
1459
1439
|
will always be truncated to microseconds.
|
|
1460
1440
|
For example, `1.12345` interpreted as microseconds will result in `timedelta(microseconds=1)`.
|
|
1461
1441
|
|
|
1462
|
-
.. versionchanged:: 2.0.0
|
|
1463
|
-
Always serializes to an integer value to avoid rounding errors.
|
|
1464
|
-
Add `precision` parameter.
|
|
1465
1442
|
.. versionchanged:: 3.17.0
|
|
1466
1443
|
Allow (de)serialization to `float` through use of a new `serialization_type` parameter.
|
|
1467
1444
|
`int` is the default to retain previous behaviour.
|
|
@@ -1944,9 +1921,6 @@ class Method(Field):
|
|
|
1944
1921
|
a value The method must take a single argument ``value``, which is the
|
|
1945
1922
|
value to deserialize.
|
|
1946
1923
|
|
|
1947
|
-
.. versionchanged:: 2.0.0
|
|
1948
|
-
Removed optional ``context`` parameter on methods. Use ``self.context`` instead.
|
|
1949
|
-
|
|
1950
1924
|
.. versionchanged:: 2.3.0
|
|
1951
1925
|
Deprecated ``method_name`` parameter in favor of ``serialize`` and allow
|
|
1952
1926
|
``serialize`` to not be passed at all.
|
|
@@ -2024,14 +1998,14 @@ class Function(Field):
|
|
|
2024
1998
|
def __init__(
|
|
2025
1999
|
self,
|
|
2026
2000
|
serialize: (
|
|
2027
|
-
|
|
2028
|
-
| typing.Callable[[typing.Any], typing.Any]
|
|
2001
|
+
typing.Callable[[typing.Any], typing.Any]
|
|
2029
2002
|
| typing.Callable[[typing.Any, dict], typing.Any]
|
|
2003
|
+
| None
|
|
2030
2004
|
) = None,
|
|
2031
2005
|
deserialize: (
|
|
2032
|
-
|
|
2033
|
-
| typing.Callable[[typing.Any], typing.Any]
|
|
2006
|
+
typing.Callable[[typing.Any], typing.Any]
|
|
2034
2007
|
| typing.Callable[[typing.Any, dict], typing.Any]
|
|
2008
|
+
| None
|
|
2035
2009
|
) = None,
|
|
2036
2010
|
**kwargs,
|
|
2037
2011
|
):
|
|
@@ -2065,8 +2039,6 @@ class Constant(Field):
|
|
|
2065
2039
|
``dump_only=True`` or ``load_only=True`` respectively.
|
|
2066
2040
|
|
|
2067
2041
|
:param constant: The constant to return for the field attribute.
|
|
2068
|
-
|
|
2069
|
-
.. versionadded:: 2.0.0
|
|
2070
2042
|
"""
|
|
2071
2043
|
|
|
2072
2044
|
_CHECK_ATTRIBUTE = False
|
marshmallow/schema.py
CHANGED
|
@@ -280,13 +280,6 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
|
|
|
280
280
|
|
|
281
281
|
.. versionchanged:: 3.0.0
|
|
282
282
|
`prefix` parameter removed.
|
|
283
|
-
|
|
284
|
-
.. versionchanged:: 2.0.0
|
|
285
|
-
`__validators__`, `__preprocessors__`, and `__data_handlers__` are removed in favor of
|
|
286
|
-
`marshmallow.decorators.validates_schema`,
|
|
287
|
-
`marshmallow.decorators.pre_load` and `marshmallow.decorators.post_dump`.
|
|
288
|
-
`__accessor__` and `__error_handler__` are deprecated. Implement the
|
|
289
|
-
`handle_error` and `get_attribute` methods instead.
|
|
290
283
|
"""
|
|
291
284
|
|
|
292
285
|
TYPE_MAPPING = {
|
|
@@ -422,7 +415,7 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
|
|
|
422
415
|
@classmethod
|
|
423
416
|
def from_dict(
|
|
424
417
|
cls,
|
|
425
|
-
fields: dict[str, ma_fields.Field
|
|
418
|
+
fields: dict[str, ma_fields.Field],
|
|
426
419
|
*,
|
|
427
420
|
name: str = "GeneratedSchema",
|
|
428
421
|
) -> type[Schema]:
|
|
@@ -444,11 +437,10 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
|
|
|
444
437
|
|
|
445
438
|
.. versionadded:: 3.0.0
|
|
446
439
|
"""
|
|
447
|
-
|
|
448
|
-
attrs["Meta"] = type(
|
|
440
|
+
Meta = type(
|
|
449
441
|
"GeneratedMeta", (getattr(cls, "Meta", object),), {"register": False}
|
|
450
442
|
)
|
|
451
|
-
schema_cls = type(name, (cls,),
|
|
443
|
+
schema_cls = type(name, (cls,), {**fields.copy(), "Meta": Meta})
|
|
452
444
|
return schema_cls
|
|
453
445
|
|
|
454
446
|
##### Override-able methods #####
|
|
@@ -463,8 +455,6 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
|
|
|
463
455
|
:param many: Value of ``many`` on dump or load.
|
|
464
456
|
:param partial: Value of ``partial`` on load.
|
|
465
457
|
|
|
466
|
-
.. versionadded:: 2.0.0
|
|
467
|
-
|
|
468
458
|
.. versionchanged:: 3.0.0rc9
|
|
469
459
|
Receives `many` and `partial` (on deserialization) as keyword arguments.
|
|
470
460
|
"""
|
|
@@ -473,8 +463,6 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
|
|
|
473
463
|
def get_attribute(self, obj: typing.Any, attr: str, default: typing.Any):
|
|
474
464
|
"""Defines how to pull values from an object to serialize.
|
|
475
465
|
|
|
476
|
-
.. versionadded:: 2.0.0
|
|
477
|
-
|
|
478
466
|
.. versionchanged:: 3.0.0a1
|
|
479
467
|
Changed position of ``obj`` and ``attr``.
|
|
480
468
|
"""
|
|
@@ -508,9 +496,6 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
|
|
|
508
496
|
:param obj: The object(s) to serialize.
|
|
509
497
|
:param bool many: `True` if ``data`` should be serialized as a collection.
|
|
510
498
|
:return: A dictionary of the serialized data
|
|
511
|
-
|
|
512
|
-
.. versionchanged:: 1.0.0
|
|
513
|
-
Renamed from ``marshal``.
|
|
514
499
|
"""
|
|
515
500
|
if many and obj is not None:
|
|
516
501
|
return [self._serialize(d, many=False) for d in obj]
|
marshmallow/utils.py
CHANGED
|
@@ -138,7 +138,7 @@ def get_fixed_timezone(offset: int | float | dt.timedelta) -> dt.timezone:
|
|
|
138
138
|
if isinstance(offset, dt.timedelta):
|
|
139
139
|
offset = offset.total_seconds() // 60
|
|
140
140
|
sign = "-" if offset < 0 else "+"
|
|
141
|
-
hhmm = "
|
|
141
|
+
hhmm = "{:02d}{:02d}".format(*divmod(abs(offset), 60))
|
|
142
142
|
name = sign + hhmm
|
|
143
143
|
return dt.timezone(dt.timedelta(minutes=offset), name)
|
|
144
144
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: marshmallow
|
|
3
|
-
Version: 3.23.
|
|
3
|
+
Version: 3.23.3
|
|
4
4
|
Summary: A lightweight library for converting complex datatypes to and from native Python datatypes.
|
|
5
5
|
Author-email: Steven Loria <sloria1@gmail.com>
|
|
6
6
|
Maintainer-email: Steven Loria <sloria1@gmail.com>, Jérôme Lafréchoux <jerome@jolimont.fr>, Jared Deckard <jared@shademaps.com>
|
|
@@ -22,7 +22,6 @@ Requires-Dist: pre-commit>=3.5,<5.0 ; extra == "dev"
|
|
|
22
22
|
Requires-Dist: sphinx==8.1.3 ; extra == "docs"
|
|
23
23
|
Requires-Dist: sphinx-issues==5.0.0 ; extra == "docs"
|
|
24
24
|
Requires-Dist: alabaster==1.0.0 ; extra == "docs"
|
|
25
|
-
Requires-Dist: sphinx-version-warning==1.1.2 ; extra == "docs"
|
|
26
25
|
Requires-Dist: autodocsumm==0.2.14 ; extra == "docs"
|
|
27
26
|
Requires-Dist: pytest ; extra == "tests"
|
|
28
27
|
Requires-Dist: simplejson ; extra == "tests"
|
|
@@ -59,19 +58,6 @@ marshmallow: simplified object serialization
|
|
|
59
58
|
|
|
60
59
|
**marshmallow** is an ORM/ODM/framework-agnostic library for converting complex datatypes, such as objects, to and from native Python datatypes.
|
|
61
60
|
|
|
62
|
-
Sponsor Message
|
|
63
|
-
===============
|
|
64
|
-
|
|
65
|
-
Input an OpenAPI spec to generate API docs that look as good as Stripe's. `Request a preview <https://form.typeform.com/to/uc55zY0F>`_ of your docs on Fern.
|
|
66
|
-
|
|
67
|
-
.. image:: https://github.com/user-attachments/assets/69916225-0d61-4bd7-b3b9-e378557673cb
|
|
68
|
-
:target: https://form.typeform.com/to/uc55zY0F
|
|
69
|
-
:align: center
|
|
70
|
-
:alt: Fern logo
|
|
71
|
-
|
|
72
|
-
Example
|
|
73
|
-
=======
|
|
74
|
-
|
|
75
61
|
.. code-block:: python
|
|
76
62
|
|
|
77
63
|
from datetime import date
|
|
@@ -4,15 +4,15 @@ marshmallow/class_registry.py,sha256=kT_kv9KT0EUclIluLD5734ms9P0e65t5aky8y3lipFI
|
|
|
4
4
|
marshmallow/decorators.py,sha256=vmQFgBgdV0s1Fw8ySyZyQKvjKBTNf5JB3SCldEIl29o,8385
|
|
5
5
|
marshmallow/error_store.py,sha256=A7AxgLMw9ffSmaxRH4x3wcBWibx-DuGH4LwSDpVn50I,2223
|
|
6
6
|
marshmallow/exceptions.py,sha256=DuARdOcirCdJxmlp16V97hQKAXOokvdW12jXtYOlGyk,2326
|
|
7
|
-
marshmallow/fields.py,sha256=
|
|
7
|
+
marshmallow/fields.py,sha256=bea24GyneKy47tNM6slFy08-R7Sycu_Yii2_bpU82ms,72098
|
|
8
8
|
marshmallow/orderedset.py,sha256=C2aAG6w1faIL1phinbAltbe3AUAnF5MN6n7fzESNDhI,2922
|
|
9
9
|
marshmallow/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
-
marshmallow/schema.py,sha256=
|
|
10
|
+
marshmallow/schema.py,sha256=UcKJdnKbpqHlgK3E2LNvnrDTFQoWWQ70Qt6rhevfu7E,48240
|
|
11
11
|
marshmallow/types.py,sha256=RDS4IfasIehvH2rGWh9e4RTBtsMp-JFFtjApajV22zc,283
|
|
12
|
-
marshmallow/utils.py,sha256
|
|
12
|
+
marshmallow/utils.py,sha256=-6jOnkuqFvb0DLeTVVifAPOklD_IdHC4LanhClCO0Hc,11897
|
|
13
13
|
marshmallow/validate.py,sha256=hS7fYC6byDHK9A7A4is0McDMZEzu6GkKke-7unLt2hE,23857
|
|
14
14
|
marshmallow/warnings.py,sha256=vHQu7AluuWqLhvlw5noXtWWbya13zDXY6JMaVSUzmDs,65
|
|
15
|
-
marshmallow-3.23.
|
|
16
|
-
marshmallow-3.23.
|
|
17
|
-
marshmallow-3.23.
|
|
18
|
-
marshmallow-3.23.
|
|
15
|
+
marshmallow-3.23.3.dist-info/LICENSE,sha256=kGtdkFHkJhRMsXOtkRZnuOvQWpxYTCwmwTWzKj7RIAE,1064
|
|
16
|
+
marshmallow-3.23.3.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
|
|
17
|
+
marshmallow-3.23.3.dist-info/METADATA,sha256=TqrYnapcPl01I17SmOHM8iDpcryV0Dba3IMkby9e4Vg,7084
|
|
18
|
+
marshmallow-3.23.3.dist-info/RECORD,,
|
|
File without changes
|