marshmallow 3.24.1__py3-none-any.whl → 3.25.0__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/base.py CHANGED
@@ -4,8 +4,8 @@ These are necessary to avoid circular imports between schema.py and fields.py.
4
4
 
5
5
  .. warning::
6
6
 
7
- This module is treated as private API.
8
- Users should not need to use this module directly.
7
+ This module is deprecated. Users should not import from this module.
8
+ Use `marshmallow.fields.Field` and `marshmallow.schema.Schema` as base classes instead.
9
9
  """
10
10
 
11
11
  from __future__ import annotations
@@ -31,3 +31,31 @@ class FieldABC(ABC):
31
31
  @abstractmethod
32
32
  def _deserialize(self, value, attr, data, **kwargs):
33
33
  pass
34
+
35
+
36
+ class SchemaABC(ABC):
37
+ """Abstract base class from which all Schemas inherit."""
38
+
39
+ @abstractmethod
40
+ def dump(self, obj, *, many: bool | None = None):
41
+ pass
42
+
43
+ @abstractmethod
44
+ def dumps(self, obj, *, many: bool | None = None):
45
+ pass
46
+
47
+ @abstractmethod
48
+ def load(self, data, *, many: bool | None = None, partial=None, unknown=None):
49
+ pass
50
+
51
+ @abstractmethod
52
+ def loads(
53
+ self,
54
+ json_data,
55
+ *,
56
+ many: bool | None = None,
57
+ partial=None,
58
+ unknown=None,
59
+ **kwargs,
60
+ ):
61
+ pass
marshmallow/decorators.py CHANGED
@@ -100,7 +100,7 @@ def validates_schema(
100
100
  """Register a schema-level validator.
101
101
 
102
102
  By default it receives a single object at a time, transparently handling the ``many``
103
- argument passed to the `Schema`'s :func:`~marshmallow.Schema.validate` call.
103
+ argument passed to the `Schema <marshmallow.Schema>`'s :func:`~marshmallow.Schema.validate` call.
104
104
  If ``pass_many=True``, the raw data (which may be a collection) is passed.
105
105
 
106
106
  If ``pass_original=True``, the original data (before unmarshalling) will be passed as
@@ -132,7 +132,7 @@ def pre_dump(
132
132
  receives the object to be serialized and returns the processed object.
133
133
 
134
134
  By default it receives a single object at a time, transparently handling the ``many``
135
- argument passed to the `Schema`'s :func:`~marshmallow.Schema.dump` call.
135
+ argument passed to the `Schema <marshmallow.Schema>`'s :func:`~marshmallow.Schema.dump` call.
136
136
  If ``pass_many=True``, the raw data (which may be a collection) is passed.
137
137
 
138
138
  .. versionchanged:: 3.0.0
@@ -150,7 +150,7 @@ def post_dump(
150
150
  receives the serialized object and returns the processed object.
151
151
 
152
152
  By default it receives a single object at a time, transparently handling the ``many``
153
- argument passed to the `Schema`'s :func:`~marshmallow.Schema.dump` call.
153
+ argument passed to the `Schema <marshmallow.Schema>`'s :func:`~marshmallow.Schema.dump` call.
154
154
  If ``pass_many=True``, the raw data (which may be a collection) is passed.
155
155
 
156
156
  If ``pass_original=True``, the original data (before serializing) will be passed as
@@ -169,7 +169,7 @@ def pre_load(
169
169
  receives the data to be deserialized and returns the processed data.
170
170
 
171
171
  By default it receives a single object at a time, transparently handling the ``many``
172
- argument passed to the `Schema`'s :func:`~marshmallow.Schema.load` call.
172
+ argument passed to the `Schema <marshmallow.Schema>`'s :func:`~marshmallow.Schema.load` call.
173
173
  If ``pass_many=True``, the raw data (which may be a collection) is passed.
174
174
 
175
175
  .. versionchanged:: 3.0.0
@@ -188,7 +188,7 @@ def post_load(
188
188
  receives the deserialized data and returns the processed data.
189
189
 
190
190
  By default it receives a single object at a time, transparently handling the ``many``
191
- argument passed to the `Schema`'s :func:`~marshmallow.Schema.load` call.
191
+ argument passed to the `Schema <marshmallow.Schema>`'s :func:`~marshmallow.Schema.load` call.
192
192
  If ``pass_many=True``, the raw data (which may be a collection) is passed.
193
193
 
194
194
  If ``pass_original=True``, the original data (before deserializing) will be passed as
marshmallow/fields.py CHANGED
@@ -139,16 +139,6 @@ class Field(FieldABC):
139
139
  "validator_failed": "Invalid value.",
140
140
  }
141
141
 
142
- def __new__(cls, *args, **kwargs):
143
- if cls is Field:
144
- warnings.warn(
145
- "`Field` should not be instantiated. Use `fields.Raw` or "
146
- "another field subclass instead.",
147
- ChangedInMarshmallow4Warning,
148
- stacklevel=2,
149
- )
150
- return super().__new__(cls)
151
-
152
142
  def __init__(
153
143
  self,
154
144
  *,
@@ -171,6 +161,13 @@ class Field(FieldABC):
171
161
  metadata: typing.Mapping[str, typing.Any] | None = None,
172
162
  **additional_metadata,
173
163
  ) -> None:
164
+ if self.__class__ is Field:
165
+ warnings.warn(
166
+ "`Field` should not be instantiated. Use `fields.Raw` or "
167
+ "another field subclass instead.",
168
+ ChangedInMarshmallow4Warning,
169
+ stacklevel=2,
170
+ )
174
171
  # handle deprecated `default` and `missing` parameters
175
172
  if default is not missing_:
176
173
  warnings.warn(
@@ -361,7 +358,7 @@ class Field(FieldABC):
361
358
 
362
359
  :param value: The value to deserialize.
363
360
  :param attr: The attribute/key in `data` to deserialize.
364
- :param data: The raw input data passed to `Schema.load`.
361
+ :param data: The raw input data passed to `Schema.load <marshmallow.Schema.load>`.
365
362
  :param kwargs: Field-specific keyword arguments.
366
363
  :raise ValidationError: If an invalid value is passed or if a required value
367
364
  is missing.
@@ -382,7 +379,7 @@ class Field(FieldABC):
382
379
 
383
380
  def _bind_to_schema(self, field_name: str, schema: Schema | Field) -> None:
384
381
  """Update field with values from its parent schema. Called by
385
- :meth:`Schema._bind_field <marshmallow.Schema._bind_field>`.
382
+ `Schema._bind_field <marshmallow.Schema._bind_field>`.
386
383
 
387
384
  :param str field_name: Field name set in schema.
388
385
  :param Schema|Field schema: Parent object.
@@ -426,7 +423,7 @@ class Field(FieldABC):
426
423
 
427
424
  :param value: The value to be deserialized.
428
425
  :param attr: The attribute/key in `data` to be deserialized.
429
- :param data: The raw input data passed to the `Schema.load`.
426
+ :param data: The raw input data passed to the `Schema.load <marshmallow.Schema.load>`.
430
427
  :param kwargs: Field-specific keyword arguments.
431
428
  :raise ValidationError: In case of formatting or validation failure.
432
429
  :return: The deserialized value.
@@ -440,7 +437,7 @@ class Field(FieldABC):
440
437
 
441
438
  @property
442
439
  def context(self) -> dict | None:
443
- """The context dictionary for the parent :class:`Schema`."""
440
+ """The context dictionary for the parent `Schema <marshmallow.Schema>`."""
444
441
  if self.parent:
445
442
  return self.parent.context
446
443
  return None
@@ -527,8 +524,9 @@ class Nested(Field):
527
524
  # No
528
525
  author = fields.Nested(UserSchema(), only=("id", "name"))
529
526
 
530
- :param nested: `Schema` instance, class, class name (string), dictionary, or callable that
531
- returns a `Schema` or dictionary. Dictionaries are converted with `Schema.from_dict`.
527
+ :param nested: `Schema <marshmallow.Schema>` instance, class, class name (string), dictionary, or callable that
528
+ returns a `Schema <marshmallow.Schema>` or dictionary.
529
+ Dictionaries are converted with `Schema.from_dict <marshmallow.Schema.from_dict>`.
532
530
  :param exclude: A list or tuple of fields to exclude.
533
531
  :param only: A list or tuple of fields to marshal. If `None`, all fields are marshalled.
534
532
  This parameter takes precedence over ``exclude``.
@@ -583,10 +581,10 @@ class Nested(Field):
583
581
 
584
582
  @property
585
583
  def schema(self) -> Schema:
586
- """The nested Schema object.
584
+ """The nested `Schema <marshmallow.Schema>` object.
587
585
 
588
586
  .. versionchanged:: 1.0.0
589
- Renamed from `serializer` to `schema`.
587
+ Renamed from ``serializer`` to ``schema``.
590
588
  """
591
589
  if not self._schema:
592
590
  # Inherit context from parent.
@@ -681,8 +679,8 @@ class Nested(Field):
681
679
  ) -> typing.Any:
682
680
  """Same as :meth:`Field._deserialize` with additional ``partial`` argument.
683
681
 
684
- :param bool|tuple partial: For nested schemas, the ``partial``
685
- parameter passed to `Schema.load`.
682
+ :param partial: For nested schemas, the ``partial``
683
+ parameter passed to `marshmallow.Schema.load`.
686
684
 
687
685
  .. versionchanged:: 3.0.0
688
686
  Add ``partial`` parameter.
@@ -713,7 +711,7 @@ class Pluck(Nested):
713
711
  dumped = AlbumSchema().dump(loaded) # => {'artist': 42}
714
712
 
715
713
  :param Schema nested: The Schema class or class name (string)
716
- to nest, or ``"self"`` to nest the :class:`Schema` within itself.
714
+ to nest, or ``"self"`` to nest the `Schema <marshmallow.Schema>` within itself.
717
715
  :param str field_name: The key to pluck a value from.
718
716
  :param kwargs: The same keyword arguments that :class:`Nested` receives.
719
717
  """
@@ -962,16 +960,13 @@ class Number(Field, typing.Generic[_NumType]):
962
960
  "too_large": "Number too large.",
963
961
  }
964
962
 
965
- def __new__(cls, *args, **kwargs):
966
- if cls is Number:
963
+ def __init__(self, *, as_string: bool = False, **kwargs):
964
+ if self.__class__ is Number:
967
965
  warnings.warn(
968
966
  "`Number` field should not be instantiated. Use `Integer`, `Float`, or `Decimal` instead.",
969
967
  ChangedInMarshmallow4Warning,
970
968
  stacklevel=2,
971
969
  )
972
- return super().__new__(cls)
973
-
974
- def __init__(self, *, as_string: bool = False, **kwargs):
975
970
  self.as_string = as_string
976
971
  super().__init__(**kwargs)
977
972
 
@@ -1578,21 +1573,18 @@ class Mapping(Field):
1578
1573
  #: Default error messages.
1579
1574
  default_error_messages = {"invalid": "Not a valid mapping type."}
1580
1575
 
1581
- def __new__(cls, *args, **kwargs):
1582
- if cls is Mapping:
1583
- warnings.warn(
1584
- "`Mapping` field should not be instantiated. Use `Dict` instead.",
1585
- ChangedInMarshmallow4Warning,
1586
- stacklevel=2,
1587
- )
1588
- return super().__new__(cls)
1589
-
1590
1576
  def __init__(
1591
1577
  self,
1592
1578
  keys: Field | type[Field] | None = None,
1593
1579
  values: Field | type[Field] | None = None,
1594
1580
  **kwargs,
1595
1581
  ):
1582
+ if self.__class__ is Mapping:
1583
+ warnings.warn(
1584
+ "`Mapping` field should not be instantiated. Use `Dict` instead.",
1585
+ ChangedInMarshmallow4Warning,
1586
+ stacklevel=2,
1587
+ )
1596
1588
  super().__init__(**kwargs)
1597
1589
  if keys is None:
1598
1590
  self.key_field = None
@@ -1965,7 +1957,7 @@ class Enum(Field):
1965
1957
 
1966
1958
 
1967
1959
  class Method(Field):
1968
- """A field that takes the value returned by a `Schema` method.
1960
+ """A field that takes the value returned by a `Schema <marshmallow.Schema>` method.
1969
1961
 
1970
1962
  :param str serialize: The name of the Schema method from which
1971
1963
  to retrieve the value. The method must take an argument ``obj``
marshmallow/schema.py CHANGED
@@ -41,7 +41,7 @@ from marshmallow.utils import (
41
41
  from marshmallow.warnings import RemovedInMarshmallow4Warning
42
42
 
43
43
 
44
- def _get_fields(attrs):
44
+ def _get_fields(attrs) -> list[tuple[str, ma_fields.Field]]:
45
45
  """Get fields from a class
46
46
 
47
47
  :param attrs: Mapping of class attributes
@@ -124,10 +124,10 @@ class SchemaMeta(ABCMeta):
124
124
  def get_declared_fields(
125
125
  mcs,
126
126
  klass: SchemaMeta,
127
- cls_fields: list,
128
- inherited_fields: list,
127
+ cls_fields: list[tuple[str, ma_fields.Field]],
128
+ inherited_fields: list[tuple[str, ma_fields.Field]],
129
129
  dict_cls: type[dict] = dict,
130
- ):
130
+ ) -> dict[str, ma_fields.Field]:
131
131
  """Returns a dictionary of field_name => `Field` pairs declared on the class.
132
132
  This is exposed mainly so that plugins can add additional fields, e.g. fields
133
133
  computed from class Meta options.
@@ -231,7 +231,7 @@ class SchemaOpts:
231
231
  self.many = getattr(meta, "many", False)
232
232
 
233
233
 
234
- class Schema(metaclass=SchemaMeta):
234
+ class Schema(base.SchemaABC, metaclass=SchemaMeta):
235
235
  """Base schema class with which to define custom schemas.
236
236
 
237
237
  Example usage:
@@ -313,7 +313,7 @@ class Schema(metaclass=SchemaMeta):
313
313
  set_class = OrderedSet
314
314
 
315
315
  # These get set by SchemaMeta
316
- opts: SchemaOpts
316
+ opts: typing.Any
317
317
  _declared_fields: dict[str, ma_fields.Field] = {}
318
318
  _hooks: dict[str, list[tuple[str, bool, dict]]] = {}
319
319
 
@@ -344,15 +344,15 @@ class Schema(metaclass=SchemaMeta):
344
344
  - ``timeformat``: Default format for `Time <fields.Time>` fields.
345
345
  - ``render_module``: Module to use for `loads <Schema.loads>` and `dumps <Schema.dumps>`.
346
346
  Defaults to `json` from the standard library.
347
- - ``ordered``: If `True`, output of `Schema.dump` will be a `collections.OrderedDict`.
347
+ - ``ordered``: If `True`, output of `Schema.dump <marshmallow.Schema.dump>` will be a `collections.OrderedDict`.
348
348
  - ``index_errors``: If `True`, errors dictionaries will include the index
349
349
  of invalid items in a collection.
350
350
  - ``load_only``: Tuple or list of fields to exclude from serialized results.
351
351
  - ``dump_only``: Tuple or list of fields to exclude from deserialization
352
352
  - ``unknown``: Whether to exclude, include, or raise an error for unknown
353
353
  fields in the data. Use `EXCLUDE`, `INCLUDE` or `RAISE`.
354
- - ``register``: Whether to register the `Schema` with marshmallow's internal
355
- class registry. Must be `True` if you intend to refer to this `Schema`
354
+ - ``register``: Whether to register the `Schema <marshmallow.Schema>` with marshmallow's internal
355
+ class registry. Must be `True` if you intend to refer to this `Schema <marshmallow.Schema>`
356
356
  by class name in `Nested` fields. Only set this to `False` when memory
357
357
  usage is critical. Defaults to `True`.
358
358
  """
@@ -428,7 +428,7 @@ class Schema(metaclass=SchemaMeta):
428
428
  *,
429
429
  name: str = "GeneratedSchema",
430
430
  ) -> type[Schema]:
431
- """Generate a `Schema` class given a dictionary of fields.
431
+ """Generate a `Schema <marshmallow.Schema>` class given a dictionary of fields.
432
432
 
433
433
  .. code-block:: python
434
434
 
@@ -1016,7 +1016,7 @@ class Schema(metaclass=SchemaMeta):
1016
1016
  self.load_fields = load_fields
1017
1017
 
1018
1018
  def on_bind_field(self, field_name: str, field_obj: ma_fields.Field) -> None:
1019
- """Hook to modify a field when it is bound to the `Schema`.
1019
+ """Hook to modify a field when it is bound to the `Schema <marshmallow.Schema>`.
1020
1020
 
1021
1021
  No-op by default.
1022
1022
  """
marshmallow/utils.py CHANGED
@@ -39,7 +39,7 @@ class _Missing:
39
39
 
40
40
 
41
41
  # Singleton value that indicates that a field's value is missing from input
42
- # dict passed to :meth:`Schema.load`. If the field's value is not required,
42
+ # dict passed to `Schema.load <marshmallow.Schema.load>`. If the field's value is not required,
43
43
  # it's ``default`` value is used.
44
44
  missing = _Missing()
45
45
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: marshmallow
3
- Version: 3.24.1
3
+ Version: 3.25.0
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>
@@ -1,18 +1,18 @@
1
1
  marshmallow/__init__.py,sha256=C-zbaQJ9dlJLJxotIqTa5OOaD6ojGNRqW8moGrMsGr8,2387
2
- marshmallow/base.py,sha256=ty-JhN__qqlJHaFVrFjMJTM5hQH6pG3xeo82Zu0sweY,719
2
+ marshmallow/base.py,sha256=39W78-rnuzzx5T95YWBEECzjtqxdUA8XzYJNHd39VLg,1362
3
3
  marshmallow/class_registry.py,sha256=ZULbtwFxnj4bbzQqfwTLyNPUpr6xAZTLFMar4YJfKJQ,3032
4
- marshmallow/decorators.py,sha256=vmQFgBgdV0s1Fw8ySyZyQKvjKBTNf5JB3SCldEIl29o,8385
4
+ marshmallow/decorators.py,sha256=B8Z-PsxWrftY4jTq3y_wt7kwlJWQI2vVQQyApMY5IeQ,8490
5
5
  marshmallow/error_store.py,sha256=A7AxgLMw9ffSmaxRH4x3wcBWibx-DuGH4LwSDpVn50I,2223
6
6
  marshmallow/exceptions.py,sha256=DuARdOcirCdJxmlp16V97hQKAXOokvdW12jXtYOlGyk,2326
7
- marshmallow/fields.py,sha256=BSqVSDWFWt0T-N477YHYCeGzQHBpiuEtTZPJ5ULPsQ8,74073
7
+ marshmallow/fields.py,sha256=Z8wS9If4tqcv0KFnbm7HS5csMiVOD6--Donv6FlMfOc,74082
8
8
  marshmallow/orderedset.py,sha256=C2aAG6w1faIL1phinbAltbe3AUAnF5MN6n7fzESNDhI,2922
9
9
  marshmallow/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- marshmallow/schema.py,sha256=FIwUiCJfdz9EMNMj9w__UIuTx0Ik_quFL_QqSWuzJ2s,48445
10
+ marshmallow/schema.py,sha256=qUY1MvcYxtEuztzjoom2fYaC7x2t16cAx4FBdgz3SDY,48696
11
11
  marshmallow/types.py,sha256=RDS4IfasIehvH2rGWh9e4RTBtsMp-JFFtjApajV22zc,283
12
- marshmallow/utils.py,sha256=-6jOnkuqFvb0DLeTVVifAPOklD_IdHC4LanhClCO0Hc,11897
12
+ marshmallow/utils.py,sha256=pLZXqQWu7PHaQrQCrgwnR8eI_-aq_BVct5CCwyygUvk,11917
13
13
  marshmallow/validate.py,sha256=t5-4Qg_XlSQgcCujf_pimKIdZE0QT63jHyQP-miJNK0,24151
14
14
  marshmallow/warnings.py,sha256=YHC0kQQBbTKCiA1FuwnbnXqrph7oKuU9BjTV4cxwnzE,192
15
- marshmallow-3.24.1.dist-info/LICENSE,sha256=kGtdkFHkJhRMsXOtkRZnuOvQWpxYTCwmwTWzKj7RIAE,1064
16
- marshmallow-3.24.1.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
17
- marshmallow-3.24.1.dist-info/METADATA,sha256=uuQri_Lj4klck4q6jwImdETasTVjrvGSpgu0I7GuM2E,7084
18
- marshmallow-3.24.1.dist-info/RECORD,,
15
+ marshmallow-3.25.0.dist-info/LICENSE,sha256=kGtdkFHkJhRMsXOtkRZnuOvQWpxYTCwmwTWzKj7RIAE,1064
16
+ marshmallow-3.25.0.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
17
+ marshmallow-3.25.0.dist-info/METADATA,sha256=yQLETlmBAzADnSDY4fAT_4zsyjlAxPlRFT6NVIovaYo,7084
18
+ marshmallow-3.25.0.dist-info/RECORD,,