marshmallow 3.26.0__py3-none-any.whl → 3.26.2__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/error_store.py +23 -12
- marshmallow/fields.py +1 -1
- marshmallow/schema.py +11 -8
- {marshmallow-3.26.0.dist-info → marshmallow-3.26.2.dist-info}/METADATA +3 -2
- {marshmallow-3.26.0.dist-info → marshmallow-3.26.2.dist-info}/RECORD +7 -7
- {marshmallow-3.26.0.dist-info → marshmallow-3.26.2.dist-info}/WHEEL +1 -1
- {marshmallow-3.26.0.dist-info → marshmallow-3.26.2.dist-info/licenses}/LICENSE +0 -0
marshmallow/error_store.py
CHANGED
|
@@ -18,6 +18,7 @@ class ErrorStore:
|
|
|
18
18
|
# field error -> store/merge error messages under field name key
|
|
19
19
|
# schema error -> if string or list, store/merge under _schema key
|
|
20
20
|
# -> if dict, store/merge with other top-level keys
|
|
21
|
+
messages = copy_containers(messages)
|
|
21
22
|
if field_name != SCHEMA or not isinstance(messages, dict):
|
|
22
23
|
messages = {field_name: messages}
|
|
23
24
|
if index is not None:
|
|
@@ -25,6 +26,14 @@ class ErrorStore:
|
|
|
25
26
|
self.errors = merge_errors(self.errors, messages)
|
|
26
27
|
|
|
27
28
|
|
|
29
|
+
def copy_containers(errors):
|
|
30
|
+
if isinstance(errors, list):
|
|
31
|
+
return [copy_containers(val) for val in errors]
|
|
32
|
+
if isinstance(errors, dict):
|
|
33
|
+
return {key: copy_containers(val) for key, val in errors.items()}
|
|
34
|
+
return errors
|
|
35
|
+
|
|
36
|
+
|
|
28
37
|
def merge_errors(errors1, errors2): # noqa: PLR0911
|
|
29
38
|
"""Deeply merge two error messages.
|
|
30
39
|
|
|
@@ -37,24 +46,26 @@ def merge_errors(errors1, errors2): # noqa: PLR0911
|
|
|
37
46
|
return errors1
|
|
38
47
|
if isinstance(errors1, list):
|
|
39
48
|
if isinstance(errors2, list):
|
|
40
|
-
|
|
49
|
+
errors1.extend(errors2)
|
|
50
|
+
return errors1
|
|
41
51
|
if isinstance(errors2, dict):
|
|
42
|
-
|
|
43
|
-
|
|
52
|
+
errors2[SCHEMA] = merge_errors(errors1, errors2.get(SCHEMA))
|
|
53
|
+
return errors2
|
|
54
|
+
errors1.append(errors2)
|
|
55
|
+
return errors1
|
|
44
56
|
if isinstance(errors1, dict):
|
|
45
|
-
if isinstance(errors2, list):
|
|
46
|
-
return dict(errors1, **{SCHEMA: merge_errors(errors1.get(SCHEMA), errors2)})
|
|
47
57
|
if isinstance(errors2, dict):
|
|
48
|
-
errors = dict(errors1)
|
|
49
58
|
for key, val in errors2.items():
|
|
50
|
-
if key in
|
|
51
|
-
|
|
59
|
+
if key in errors1:
|
|
60
|
+
errors1[key] = merge_errors(errors1[key], val)
|
|
52
61
|
else:
|
|
53
|
-
|
|
54
|
-
return
|
|
55
|
-
|
|
62
|
+
errors1[key] = val
|
|
63
|
+
return errors1
|
|
64
|
+
errors1[SCHEMA] = merge_errors(errors1.get(SCHEMA), errors2)
|
|
65
|
+
return errors1
|
|
56
66
|
if isinstance(errors2, list):
|
|
57
67
|
return [errors1, *errors2]
|
|
58
68
|
if isinstance(errors2, dict):
|
|
59
|
-
|
|
69
|
+
errors2[SCHEMA] = merge_errors(errors1, errors2.get(SCHEMA))
|
|
70
|
+
return errors2
|
|
60
71
|
return [errors1, errors2]
|
marshmallow/fields.py
CHANGED
|
@@ -675,7 +675,7 @@ class Nested(Field):
|
|
|
675
675
|
self,
|
|
676
676
|
value: typing.Any,
|
|
677
677
|
attr: str | None,
|
|
678
|
-
data: typing.Mapping[str, typing.Any] | None
|
|
678
|
+
data: typing.Mapping[str, typing.Any] | None,
|
|
679
679
|
partial: bool | types.StrSequenceOrSet | None = None,
|
|
680
680
|
**kwargs,
|
|
681
681
|
) -> typing.Any:
|
marshmallow/schema.py
CHANGED
|
@@ -374,7 +374,7 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
|
|
|
374
374
|
|
|
375
375
|
class MySchema2(Schema):
|
|
376
376
|
# Type checkers will check attributes
|
|
377
|
-
class Meta(Schema.
|
|
377
|
+
class Meta(Schema.Meta):
|
|
378
378
|
additional = True # Incompatible types in assignment
|
|
379
379
|
|
|
380
380
|
.. versionremoved:: 3.0.0b7 Remove ``strict``.
|
|
@@ -384,9 +384,9 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
|
|
|
384
384
|
.. versionchanged:: 3.26.0 Deprecate `ordered`. Field order is preserved by default.
|
|
385
385
|
"""
|
|
386
386
|
|
|
387
|
-
fields: typing.ClassVar[tuple[
|
|
387
|
+
fields: typing.ClassVar[tuple[str, ...] | list[str]]
|
|
388
388
|
"""Fields to include in the (de)serialized result"""
|
|
389
|
-
additional: typing.ClassVar[tuple[
|
|
389
|
+
additional: typing.ClassVar[tuple[str, ...] | list[str]]
|
|
390
390
|
"""Fields to include in addition to the explicitly declared fields.
|
|
391
391
|
`additional <marshmallow.Schema.Meta.additional>` and `fields <marshmallow.Schema.Meta.fields>`
|
|
392
392
|
are mutually-exclusive options.
|
|
@@ -396,7 +396,7 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
|
|
|
396
396
|
usually better to define fields as class variables, but you may need to
|
|
397
397
|
use this option, e.g., if your fields are Python keywords.
|
|
398
398
|
"""
|
|
399
|
-
exclude: typing.ClassVar[tuple[
|
|
399
|
+
exclude: typing.ClassVar[tuple[str, ...] | list[str]]
|
|
400
400
|
"""Fields to exclude in the serialized result.
|
|
401
401
|
Nested fields can be represented with dot delimiters.
|
|
402
402
|
"""
|
|
@@ -408,7 +408,10 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
|
|
|
408
408
|
"""Default format for `DateTime <marshmallow.fields.DateTime>` fields."""
|
|
409
409
|
timeformat: typing.ClassVar[str]
|
|
410
410
|
"""Default format for `Time <marshmallow.fields.Time>` fields."""
|
|
411
|
-
|
|
411
|
+
|
|
412
|
+
# FIXME: Use a more constrained type here.
|
|
413
|
+
# ClassVar[RenderModule] doesn't work.
|
|
414
|
+
render_module: typing.Any
|
|
412
415
|
""" Module to use for `loads <marshmallow.Schema.loads>` and `dumps <marshmallow.Schema.dumps>`.
|
|
413
416
|
Defaults to `json` from the standard library.
|
|
414
417
|
"""
|
|
@@ -416,9 +419,9 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
|
|
|
416
419
|
"""If `True`, `Schema.dump <marshmallow.Schema.dump>` is a `collections.OrderedDict`."""
|
|
417
420
|
index_errors: typing.ClassVar[bool]
|
|
418
421
|
"""If `True`, errors dictionaries will include the index of invalid items in a collection."""
|
|
419
|
-
load_only: typing.ClassVar[tuple[
|
|
422
|
+
load_only: typing.ClassVar[tuple[str, ...] | list[str]]
|
|
420
423
|
"""Fields to exclude from serialized results"""
|
|
421
|
-
dump_only: typing.ClassVar[tuple[
|
|
424
|
+
dump_only: typing.ClassVar[tuple[str, ...] | list[str]]
|
|
422
425
|
"""Fields to exclude from serialized results"""
|
|
423
426
|
unknown: typing.ClassVar[str]
|
|
424
427
|
"""Whether to exclude, include, or raise an error for unknown fields in the data.
|
|
@@ -1136,7 +1139,7 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
|
|
|
1136
1139
|
msg = (
|
|
1137
1140
|
f'Field for "{field_name}" must be declared as a '
|
|
1138
1141
|
"Field instance, not a class. "
|
|
1139
|
-
f'Did you mean "fields.{field_obj.__name__}()"?'
|
|
1142
|
+
f'Did you mean "fields.{field_obj.__name__}()"?'
|
|
1140
1143
|
)
|
|
1141
1144
|
raise TypeError(msg) from error
|
|
1142
1145
|
raise
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: marshmallow
|
|
3
|
-
Version: 3.26.
|
|
3
|
+
Version: 3.26.2
|
|
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>
|
|
@@ -15,6 +15,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.11
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.12
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
License-File: LICENSE
|
|
18
19
|
Requires-Dist: packaging>=17.0
|
|
19
20
|
Requires-Dist: marshmallow[tests] ; extra == "dev"
|
|
20
21
|
Requires-Dist: tox ; extra == "dev"
|
|
@@ -2,17 +2,17 @@ marshmallow/__init__.py,sha256=TU1arjtOLs87YDfW4Z35YVbaY2CUXK-VgylcuL8LaQg,2387
|
|
|
2
2
|
marshmallow/base.py,sha256=39W78-rnuzzx5T95YWBEECzjtqxdUA8XzYJNHd39VLg,1362
|
|
3
3
|
marshmallow/class_registry.py,sha256=HTC9srCEaRsiy5L_vUKQso7IQfeZeRXxZfz4_2NitoM,3029
|
|
4
4
|
marshmallow/decorators.py,sha256=pMjGPaXBZCRfAdQS3Bz5ieTZGA3BOv61FdTPsLwCtMQ,8749
|
|
5
|
-
marshmallow/error_store.py,sha256=
|
|
5
|
+
marshmallow/error_store.py,sha256=5-62el8Ey2w59x8FDhUC5afPu63NXjumKiAagAGL9bY,2444
|
|
6
6
|
marshmallow/exceptions.py,sha256=DuARdOcirCdJxmlp16V97hQKAXOokvdW12jXtYOlGyk,2326
|
|
7
|
-
marshmallow/fields.py,sha256=
|
|
7
|
+
marshmallow/fields.py,sha256=TKVxFY9hLpq7ch6_HEb1be5uPw0fgs-uC4n5o_fTkg8,74756
|
|
8
8
|
marshmallow/orderedset.py,sha256=-Lq83AWIIFs2bxptDwkHtfQ63ebX3WD3R6N3B5rRnVI,2936
|
|
9
9
|
marshmallow/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
-
marshmallow/schema.py,sha256=
|
|
10
|
+
marshmallow/schema.py,sha256=I5_eEaaJPs6pCP3Hk7UmA6LpIY_AGq5b8mQN9e-XD_c,52177
|
|
11
11
|
marshmallow/types.py,sha256=VY0_D-Xou7nKjcvWB1iccm8cZtxI3rkis1nhNelNn5Q,979
|
|
12
12
|
marshmallow/utils.py,sha256=tLzu9FDL3Ph51qKsoqWIyPSwg8dZ8rzjeXXGLUndHFE,11943
|
|
13
13
|
marshmallow/validate.py,sha256=Fx3F8F20dBGg-Wrv84Chx5SYedX9E0l592hR4MxS0kQ,24652
|
|
14
14
|
marshmallow/warnings.py,sha256=YHC0kQQBbTKCiA1FuwnbnXqrph7oKuU9BjTV4cxwnzE,192
|
|
15
|
-
marshmallow-3.26.
|
|
16
|
-
marshmallow-3.26.
|
|
17
|
-
marshmallow-3.26.
|
|
18
|
-
marshmallow-3.26.
|
|
15
|
+
marshmallow-3.26.2.dist-info/licenses/LICENSE,sha256=kGtdkFHkJhRMsXOtkRZnuOvQWpxYTCwmwTWzKj7RIAE,1064
|
|
16
|
+
marshmallow-3.26.2.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
|
|
17
|
+
marshmallow-3.26.2.dist-info/METADATA,sha256=4EzTZh8SGuZS7Y-CJ4kCER__GppWvipXWz59tT_Waxs,7332
|
|
18
|
+
marshmallow-3.26.2.dist-info/RECORD,,
|
|
File without changes
|