marshmallow 3.22.0__py3-none-any.whl → 3.23.1__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.
@@ -17,7 +17,7 @@ from marshmallow.exceptions import RegistryError
17
17
  if typing.TYPE_CHECKING:
18
18
  from marshmallow import Schema
19
19
 
20
- SchemaType = typing.Type[Schema]
20
+ SchemaType = type[Schema]
21
21
 
22
22
  # {
23
23
  # <class_name>: <list of class objects>
marshmallow/fields.py CHANGED
@@ -33,6 +33,10 @@ from marshmallow.utils import (
33
33
  from marshmallow.validate import And, Length
34
34
  from marshmallow.warnings import RemovedInMarshmallow4Warning
35
35
 
36
+ if typing.TYPE_CHECKING:
37
+ from marshmallow.schema import SchemaMeta
38
+
39
+
36
40
  __all__ = [
37
41
  "Field",
38
42
  "Raw",
@@ -535,10 +539,10 @@ class Nested(Field):
535
539
  def __init__(
536
540
  self,
537
541
  nested: SchemaABC
538
- | type
542
+ | SchemaMeta
539
543
  | str
540
- | dict[str, Field | type]
541
- | typing.Callable[[], SchemaABC | type | dict[str, Field | type]],
544
+ | dict[str, Field | type[Field]]
545
+ | typing.Callable[[], SchemaABC | SchemaMeta | dict[str, Field | type[Field]]],
542
546
  *,
543
547
  dump_default: typing.Any = missing_,
544
548
  default: typing.Any = missing_,
@@ -700,7 +704,7 @@ class Pluck(Nested):
700
704
 
701
705
  def __init__(
702
706
  self,
703
- nested: SchemaABC | type | str | typing.Callable[[], SchemaABC],
707
+ nested: SchemaABC | SchemaMeta | str | typing.Callable[[], SchemaABC],
704
708
  field_name: str,
705
709
  **kwargs,
706
710
  ):
@@ -751,7 +755,7 @@ class List(Field):
751
755
  #: Default error messages.
752
756
  default_error_messages = {"invalid": "Not a valid list."}
753
757
 
754
- def __init__(self, cls_or_instance: Field | type, **kwargs):
758
+ def __init__(self, cls_or_instance: Field | type[Field], **kwargs):
755
759
  super().__init__(**kwargs)
756
760
  try:
757
761
  self.inner = resolve_field_instance(cls_or_instance)
@@ -1236,7 +1240,7 @@ class DateTime(Field):
1236
1240
  "rfc822": utils.rfcformat,
1237
1241
  "timestamp": utils.timestamp,
1238
1242
  "timestamp_ms": utils.timestamp_ms,
1239
- } # type: typing.Dict[str, typing.Callable[[typing.Any], str | float]]
1243
+ } # type: dict[str, typing.Callable[[typing.Any], str | float]]
1240
1244
 
1241
1245
  DESERIALIZATION_FUNCS = {
1242
1246
  "iso": utils.from_iso_datetime,
@@ -1245,7 +1249,7 @@ class DateTime(Field):
1245
1249
  "rfc822": utils.from_rfc,
1246
1250
  "timestamp": utils.from_timestamp,
1247
1251
  "timestamp_ms": utils.from_timestamp_ms,
1248
- } # type: typing.Dict[str, typing.Callable[[str], typing.Any]]
1252
+ } # type: dict[str, typing.Callable[[str], typing.Any]]
1249
1253
 
1250
1254
  DEFAULT_FORMAT = "iso"
1251
1255
 
@@ -1555,8 +1559,8 @@ class Mapping(Field):
1555
1559
 
1556
1560
  def __init__(
1557
1561
  self,
1558
- keys: Field | type | None = None,
1559
- values: Field | type | None = None,
1562
+ keys: Field | type[Field] | None = None,
1563
+ values: Field | type[Field] | None = None,
1560
1564
  **kwargs,
1561
1565
  ):
1562
1566
  super().__init__(**kwargs)
@@ -1688,6 +1692,7 @@ class Url(String):
1688
1692
 
1689
1693
  :param default: Default value for the field if the attribute is not set.
1690
1694
  :param relative: Whether to allow relative URLs.
1695
+ :param absolute: Whether to allow absolute URLs.
1691
1696
  :param require_tld: Whether to reject non-FQDN hostnames.
1692
1697
  :param schemes: Valid schemes. By default, ``http``, ``https``,
1693
1698
  ``ftp``, and ``ftps`` are allowed.
@@ -1878,7 +1883,7 @@ class Enum(Field):
1878
1883
  self,
1879
1884
  enum: type[EnumType],
1880
1885
  *,
1881
- by_value: bool | Field | type = False,
1886
+ by_value: bool | Field | type[Field] = False,
1882
1887
  **kwargs,
1883
1888
  ):
1884
1889
  super().__init__(**kwargs)
marshmallow/schema.py CHANGED
@@ -40,8 +40,6 @@ from marshmallow.utils import (
40
40
  )
41
41
  from marshmallow.warnings import RemovedInMarshmallow4Warning
42
42
 
43
- _T = typing.TypeVar("_T")
44
-
45
43
 
46
44
  def _get_fields(attrs):
47
45
  """Get fields from a class
@@ -57,7 +55,7 @@ def _get_fields(attrs):
57
55
 
58
56
  # This function allows Schemas to inherit from non-Schema classes and ensures
59
57
  # inheritance according to the MRO
60
- def _get_fields_by_mro(klass):
58
+ def _get_fields_by_mro(klass: SchemaMeta):
61
59
  """Collect fields from a class, following its method resolution order. The
62
60
  class itself is excluded from the search; only its parents are checked. Get
63
61
  fields from ``_declared_fields`` if available, else use ``__dict__``.
@@ -125,10 +123,10 @@ class SchemaMeta(ABCMeta):
125
123
  @classmethod
126
124
  def get_declared_fields(
127
125
  mcs,
128
- klass: type,
126
+ klass: SchemaMeta,
129
127
  cls_fields: list,
130
128
  inherited_fields: list,
131
- dict_cls: type = dict,
129
+ dict_cls: type[dict] = dict,
132
130
  ):
133
131
  """Returns a dictionary of field_name => `Field` pairs declared on the class.
134
132
  This is exposed mainly so that plugins can add additional fields, e.g. fields
@@ -156,7 +154,7 @@ class SchemaMeta(ABCMeta):
156
154
  """
157
155
  mro = inspect.getmro(cls)
158
156
 
159
- hooks = defaultdict(list) # type: typing.Dict[str, typing.List[typing.Tuple[str, bool, dict]]]
157
+ hooks = defaultdict(list) # type: dict[str, list[tuple[str, bool, dict]]]
160
158
 
161
159
  for attr_name in dir(cls):
162
160
  # Need to look up the actual descriptor, not whatever might be
@@ -176,7 +174,7 @@ class SchemaMeta(ABCMeta):
176
174
  continue
177
175
 
178
176
  try:
179
- hook_config = attr.__marshmallow_hook__ # type: typing.Dict[str, typing.List[typing.Tuple[bool, dict]]]
177
+ hook_config = attr.__marshmallow_hook__ # type: dict[str, list[tuple[bool, dict]]]
180
178
  except AttributeError:
181
179
  pass
182
180
  else:
@@ -306,14 +304,14 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
306
304
  dt.date: ma_fields.Date,
307
305
  dt.timedelta: ma_fields.TimeDelta,
308
306
  decimal.Decimal: ma_fields.Decimal,
309
- } # type: typing.Dict[type, typing.Type[ma_fields.Field]]
307
+ } # type: dict[type, typing.Type[ma_fields.Field]]
310
308
  #: Overrides for default schema-level error messages
311
- error_messages = {} # type: typing.Dict[str, str]
309
+ error_messages = {} # type: dict[str, str]
312
310
 
313
311
  _default_error_messages = {
314
312
  "type": "Invalid input type.",
315
313
  "unknown": "Unknown field.",
316
- } # type: typing.Dict[str, str]
314
+ } # type: dict[str, str]
317
315
 
318
316
  OPTIONS_CLASS = SchemaOpts # type: type
319
317
 
@@ -321,8 +319,8 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
321
319
 
322
320
  # These get set by SchemaMeta
323
321
  opts = None # type: SchemaOpts
324
- _declared_fields = {} # type: typing.Dict[str, ma_fields.Field]
325
- _hooks = {} # type: typing.Dict[str, typing.List[typing.Tuple[str, bool, dict]]]
322
+ _declared_fields = {} # type: dict[str, ma_fields.Field]
323
+ _hooks = {} # type: dict[str, list[tuple[str, bool, dict]]]
326
324
 
327
325
  class Meta:
328
326
  """Options object for a Schema.
@@ -400,9 +398,9 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
400
398
  self.context = context or {}
401
399
  self._normalize_nested_options()
402
400
  #: Dictionary mapping field_names -> :class:`Field` objects
403
- self.fields = {} # type: typing.Dict[str, ma_fields.Field]
404
- self.load_fields = {} # type: typing.Dict[str, ma_fields.Field]
405
- self.dump_fields = {} # type: typing.Dict[str, ma_fields.Field]
401
+ self.fields = {} # type: dict[str, ma_fields.Field]
402
+ self.load_fields = {} # type: dict[str, ma_fields.Field]
403
+ self.dump_fields = {} # type: dict[str, ma_fields.Field]
406
404
  self._init_fields()
407
405
  messages = {}
408
406
  messages.update(self._default_error_messages)
@@ -415,16 +413,19 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
415
413
  return f"<{self.__class__.__name__}(many={self.many})>"
416
414
 
417
415
  @property
418
- def dict_class(self) -> type:
419
- return OrderedDict if self.ordered else dict
416
+ def dict_class(self) -> type[dict]:
417
+ if self.ordered:
418
+ return OrderedDict
419
+ else:
420
+ return dict
420
421
 
421
422
  @classmethod
422
423
  def from_dict(
423
424
  cls,
424
- fields: dict[str, ma_fields.Field | type],
425
+ fields: dict[str, ma_fields.Field | type[ma_fields.Field]],
425
426
  *,
426
427
  name: str = "GeneratedSchema",
427
- ) -> type:
428
+ ) -> type[Schema]:
428
429
  """Generate a `Schema` class given a dictionary of fields.
429
430
 
430
431
  .. code-block:: python
@@ -501,7 +502,7 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
501
502
  return error.valid_data or missing
502
503
  return value
503
504
 
504
- def _serialize(self, obj: _T | typing.Iterable[_T], *, many: bool = False):
505
+ def _serialize(self, obj: typing.Any, *, many: bool = False):
505
506
  """Serialize ``obj``.
506
507
 
507
508
  :param obj: The object(s) to serialize.
@@ -512,10 +513,7 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
512
513
  Renamed from ``marshal``.
513
514
  """
514
515
  if many and obj is not None:
515
- return [
516
- self._serialize(d, many=False)
517
- for d in typing.cast(typing.Iterable[_T], obj)
518
- ]
516
+ return [self._serialize(d, many=False) for d in obj]
519
517
  ret = self.dict_class()
520
518
  for attr_name, field_obj in self.dump_fields.items():
521
519
  value = field_obj.serialize(attr_name, obj, accessor=self.get_attribute)
@@ -588,7 +586,7 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
588
586
  partial=None,
589
587
  unknown=RAISE,
590
588
  index=None,
591
- ) -> _T | list[_T]:
589
+ ) -> typing.Any | list[typing.Any]:
592
590
  """Deserialize ``data``.
593
591
 
594
592
  :param dict data: The data to deserialize.
@@ -602,26 +600,24 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
602
600
  fields in the data. Use `EXCLUDE`, `INCLUDE` or `RAISE`.
603
601
  :param int index: Index of the item being serialized (for storing errors) if
604
602
  serializing a collection, otherwise `None`.
605
- :return: A dictionary of the deserialized data.
603
+ :return: The deserialized data as `dict_class` instance or list of `dict_class`
604
+ instances if `many` is `True`.
606
605
  """
607
606
  index_errors = self.opts.index_errors
608
607
  index = index if index_errors else None
609
608
  if many:
610
609
  if not is_collection(data):
611
610
  error_store.store_error([self.error_messages["type"]], index=index)
612
- ret_l = [] # type: typing.List[_T]
611
+ ret_l = []
613
612
  else:
614
613
  ret_l = [
615
- typing.cast(
616
- _T,
617
- self._deserialize(
618
- typing.cast(typing.Mapping[str, typing.Any], d),
619
- error_store=error_store,
620
- many=False,
621
- partial=partial,
622
- unknown=unknown,
623
- index=idx,
624
- ),
614
+ self._deserialize(
615
+ typing.cast(dict, d),
616
+ error_store=error_store,
617
+ many=False,
618
+ partial=partial,
619
+ unknown=unknown,
620
+ index=idx,
625
621
  )
626
622
  for idx, d in enumerate(data)
627
623
  ]
@@ -806,7 +802,7 @@ class Schema(base.SchemaABC, metaclass=SchemaMeta):
806
802
  try:
807
803
  self._do_load(data, many=many, partial=partial, postprocess=False)
808
804
  except ValidationError as exc:
809
- return typing.cast(typing.Dict[str, typing.List[str]], exc.messages)
805
+ return typing.cast(dict[str, list[str]], exc.messages)
810
806
  return {}
811
807
 
812
808
  ##### Private Helpers #####
@@ -1,31 +1,30 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: marshmallow
3
- Version: 3.22.0
3
+ Version: 3.23.1
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>
7
- Requires-Python: >=3.8
7
+ Requires-Python: >=3.9
8
8
  Description-Content-Type: text/x-rst
9
9
  Classifier: Development Status :: 5 - Production/Stable
10
10
  Classifier: Intended Audience :: Developers
11
11
  Classifier: License :: OSI Approved :: MIT License
12
12
  Classifier: Programming Language :: Python :: 3
13
- Classifier: Programming Language :: Python :: 3.8
14
13
  Classifier: Programming Language :: Python :: 3.9
15
14
  Classifier: Programming Language :: Python :: 3.10
16
15
  Classifier: Programming Language :: Python :: 3.11
17
16
  Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
18
  Requires-Dist: packaging>=17.0
19
19
  Requires-Dist: marshmallow[tests] ; extra == "dev"
20
20
  Requires-Dist: tox ; extra == "dev"
21
- Requires-Dist: pre-commit~=3.5 ; extra == "dev"
22
- Requires-Dist: sphinx==8.0.2 ; extra == "docs"
23
- Requires-Dist: sphinx-issues==4.1.0 ; extra == "docs"
21
+ Requires-Dist: pre-commit>=3.5,<5.0 ; extra == "dev"
22
+ Requires-Dist: sphinx==8.1.3 ; extra == "docs"
23
+ Requires-Dist: sphinx-issues==5.0.0 ; extra == "docs"
24
24
  Requires-Dist: alabaster==1.0.0 ; extra == "docs"
25
25
  Requires-Dist: sphinx-version-warning==1.1.2 ; extra == "docs"
26
- Requires-Dist: autodocsumm==0.2.13 ; extra == "docs"
26
+ Requires-Dist: autodocsumm==0.2.14 ; extra == "docs"
27
27
  Requires-Dist: pytest ; extra == "tests"
28
- Requires-Dist: pytz ; extra == "tests"
29
28
  Requires-Dist: simplejson ; extra == "tests"
30
29
  Project-URL: Changelog, https://marshmallow.readthedocs.io/en/latest/changelog.html
31
30
  Project-URL: Funding, https://opencollective.com/marshmallow
@@ -60,6 +59,19 @@ marshmallow: simplified object serialization
60
59
 
61
60
  **marshmallow** is an ORM/ODM/framework-agnostic library for converting complex datatypes, such as objects, to and from native Python datatypes.
62
61
 
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
+
63
75
  .. code-block:: python
64
76
 
65
77
  from datetime import date
@@ -102,17 +114,11 @@ Get It Now
102
114
 
103
115
  $ pip install -U marshmallow
104
116
 
105
-
106
117
  Documentation
107
118
  =============
108
119
 
109
120
  Full documentation is available at https://marshmallow.readthedocs.io/ .
110
121
 
111
- Requirements
112
- ============
113
-
114
- - Python >= 3.8
115
-
116
122
  Ecosystem
117
123
  =========
118
124
 
@@ -1,18 +1,18 @@
1
1
  marshmallow/__init__.py,sha256=C-zbaQJ9dlJLJxotIqTa5OOaD6ojGNRqW8moGrMsGr8,2387
2
2
  marshmallow/base.py,sha256=jZ68DZxxSCvRg2GTcxQcf2JjTxqEn-xFNrBEMK3CinU,1346
3
- marshmallow/class_registry.py,sha256=Uvg-Obos0MejwTrpOHNEH4VF_SfGXKgR-4F2LnCbt1A,2811
3
+ marshmallow/class_registry.py,sha256=kT_kv9KT0EUclIluLD5734ms9P0e65t5aky8y3lipFI,2804
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=3mWgT1TiLzKgdhgWTJYsGe6lVgUz02g8sb63FEEn5hc,72995
7
+ marshmallow/fields.py,sha256=O2CQto3QgSvCK_loCoGZZ_0Ieot8uLGm6vnnlJzzvT8,73167
8
8
  marshmallow/orderedset.py,sha256=C2aAG6w1faIL1phinbAltbe3AUAnF5MN6n7fzESNDhI,2922
9
9
  marshmallow/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- marshmallow/schema.py,sha256=l71HiKwPPfwIMQxXkr4oUoKybdT_vImoLkuj6ZTnUyg,49044
10
+ marshmallow/schema.py,sha256=C4BsYkDBQbdgDA6w39oSqVlsDx4NfbkT_XtSIKcqxIo,48812
11
11
  marshmallow/types.py,sha256=RDS4IfasIehvH2rGWh9e4RTBtsMp-JFFtjApajV22zc,283
12
12
  marshmallow/utils.py,sha256=sWciesZ6tS08uX9Z9fzu2lbuut5eh8TKABU-TwgqSms,11886
13
13
  marshmallow/validate.py,sha256=hS7fYC6byDHK9A7A4is0McDMZEzu6GkKke-7unLt2hE,23857
14
14
  marshmallow/warnings.py,sha256=vHQu7AluuWqLhvlw5noXtWWbya13zDXY6JMaVSUzmDs,65
15
- marshmallow-3.22.0.dist-info/LICENSE,sha256=kGtdkFHkJhRMsXOtkRZnuOvQWpxYTCwmwTWzKj7RIAE,1064
16
- marshmallow-3.22.0.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
17
- marshmallow-3.22.0.dist-info/METADATA,sha256=7rCpX93_5nP-u7BEcVtaAa56-99xuwHcg-ALtEgm4-w,7225
18
- marshmallow-3.22.0.dist-info/RECORD,,
15
+ marshmallow-3.23.1.dist-info/LICENSE,sha256=kGtdkFHkJhRMsXOtkRZnuOvQWpxYTCwmwTWzKj7RIAE,1064
16
+ marshmallow-3.23.1.dist-info/WHEEL,sha256=-ta_u8-23-bwm4JkHhR_rJkpb_X1cxtvIsLH0KOv1sU,82
17
+ marshmallow-3.23.1.dist-info/METADATA,sha256=TxU1K0BGtqGb3Ri_EMHXnOfyNiZcl8lHJhsMFHCVOiA,7537
18
+ marshmallow-3.23.1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: flit 3.9.0
2
+ Generator: flit 3.10.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any