marshmallow 3.22.0__tar.gz → 3.23.0__tar.gz

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.
Files changed (75) hide show
  1. {marshmallow-3.22.0 → marshmallow-3.23.0}/CHANGELOG.rst +12 -0
  2. {marshmallow-3.22.0 → marshmallow-3.23.0}/PKG-INFO +20 -8
  3. {marshmallow-3.22.0 → marshmallow-3.23.0}/README.rst +14 -1
  4. marshmallow-3.23.0/docs/_static/css/sponsor-message.css +15 -0
  5. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/conf.py +1 -1
  6. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/index.rst +9 -0
  7. {marshmallow-3.22.0 → marshmallow-3.23.0}/pyproject.toml +7 -7
  8. {marshmallow-3.22.0 → marshmallow-3.23.0}/src/marshmallow/class_registry.py +1 -1
  9. {marshmallow-3.22.0 → marshmallow-3.23.0}/src/marshmallow/fields.py +14 -10
  10. {marshmallow-3.22.0 → marshmallow-3.23.0}/src/marshmallow/schema.py +34 -38
  11. {marshmallow-3.22.0 → marshmallow-3.23.0}/tests/base.py +3 -5
  12. {marshmallow-3.22.0 → marshmallow-3.23.0}/tests/test_deserialization.py +2 -2
  13. {marshmallow-3.22.0 → marshmallow-3.23.0}/tests/test_serialization.py +4 -4
  14. {marshmallow-3.22.0 → marshmallow-3.23.0}/tests/test_utils.py +4 -4
  15. {marshmallow-3.22.0 → marshmallow-3.23.0}/tox.ini +1 -1
  16. {marshmallow-3.22.0 → marshmallow-3.23.0}/CONTRIBUTING.rst +0 -0
  17. {marshmallow-3.22.0 → marshmallow-3.23.0}/LICENSE +0 -0
  18. {marshmallow-3.22.0 → marshmallow-3.23.0}/NOTICE +0 -0
  19. {marshmallow-3.22.0 → marshmallow-3.23.0}/SECURITY.md +0 -0
  20. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/.gitignore +0 -0
  21. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/_static/css/versionwarning.css +0 -0
  22. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/_static/marshmallow-logo.png +0 -0
  23. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/_templates/donate.html +0 -0
  24. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/_templates/useful-links.html +0 -0
  25. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/about.rst.inc +0 -0
  26. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/api_reference.rst +0 -0
  27. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/authors.rst +0 -0
  28. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/changelog.rst +0 -0
  29. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/code_of_conduct.rst +0 -0
  30. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/contributing.rst +0 -0
  31. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/custom_fields.rst +0 -0
  32. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/dashing.json +0 -0
  33. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/ecosystem.rst +0 -0
  34. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/examples.rst +0 -0
  35. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/extending.rst +0 -0
  36. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/install.rst +0 -0
  37. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/kudos.rst +0 -0
  38. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/license.rst +0 -0
  39. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/marshmallow.class_registry.rst +0 -0
  40. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/marshmallow.decorators.rst +0 -0
  41. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/marshmallow.error_store.rst +0 -0
  42. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/marshmallow.exceptions.rst +0 -0
  43. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/marshmallow.fields.rst +0 -0
  44. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/marshmallow.schema.rst +0 -0
  45. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/marshmallow.utils.rst +0 -0
  46. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/marshmallow.validate.rst +0 -0
  47. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/nesting.rst +0 -0
  48. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/quickstart.rst +0 -0
  49. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/upgrading.rst +0 -0
  50. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/whos_using.rst +0 -0
  51. {marshmallow-3.22.0 → marshmallow-3.23.0}/docs/why.rst +0 -0
  52. {marshmallow-3.22.0 → marshmallow-3.23.0}/src/marshmallow/__init__.py +0 -0
  53. {marshmallow-3.22.0 → marshmallow-3.23.0}/src/marshmallow/base.py +0 -0
  54. {marshmallow-3.22.0 → marshmallow-3.23.0}/src/marshmallow/decorators.py +0 -0
  55. {marshmallow-3.22.0 → marshmallow-3.23.0}/src/marshmallow/error_store.py +0 -0
  56. {marshmallow-3.22.0 → marshmallow-3.23.0}/src/marshmallow/exceptions.py +0 -0
  57. {marshmallow-3.22.0 → marshmallow-3.23.0}/src/marshmallow/orderedset.py +0 -0
  58. {marshmallow-3.22.0 → marshmallow-3.23.0}/src/marshmallow/py.typed +0 -0
  59. {marshmallow-3.22.0 → marshmallow-3.23.0}/src/marshmallow/types.py +0 -0
  60. {marshmallow-3.22.0 → marshmallow-3.23.0}/src/marshmallow/utils.py +0 -0
  61. {marshmallow-3.22.0 → marshmallow-3.23.0}/src/marshmallow/validate.py +0 -0
  62. {marshmallow-3.22.0 → marshmallow-3.23.0}/src/marshmallow/warnings.py +0 -0
  63. {marshmallow-3.22.0 → marshmallow-3.23.0}/tests/__init__.py +0 -0
  64. {marshmallow-3.22.0 → marshmallow-3.23.0}/tests/conftest.py +0 -0
  65. {marshmallow-3.22.0 → marshmallow-3.23.0}/tests/foo_serializer.py +0 -0
  66. {marshmallow-3.22.0 → marshmallow-3.23.0}/tests/mypy_test_cases/test_validation_error.py +0 -0
  67. {marshmallow-3.22.0 → marshmallow-3.23.0}/tests/test_decorators.py +0 -0
  68. {marshmallow-3.22.0 → marshmallow-3.23.0}/tests/test_error_store.py +0 -0
  69. {marshmallow-3.22.0 → marshmallow-3.23.0}/tests/test_exceptions.py +0 -0
  70. {marshmallow-3.22.0 → marshmallow-3.23.0}/tests/test_fields.py +0 -0
  71. {marshmallow-3.22.0 → marshmallow-3.23.0}/tests/test_options.py +0 -0
  72. {marshmallow-3.22.0 → marshmallow-3.23.0}/tests/test_registry.py +0 -0
  73. {marshmallow-3.22.0 → marshmallow-3.23.0}/tests/test_schema.py +0 -0
  74. {marshmallow-3.22.0 → marshmallow-3.23.0}/tests/test_validate.py +0 -0
  75. {marshmallow-3.22.0 → marshmallow-3.23.0}/tests/test_version_attributes.py +0 -0
@@ -1,6 +1,18 @@
1
1
  Changelog
2
2
  ---------
3
3
 
4
+ 3.23.0 (2024-10-17)
5
+ *******************
6
+
7
+ Features:
8
+
9
+ - Typing: replace "type" with specific metaclass for ``Schema`` and ``Field``.
10
+
11
+ Other changes:
12
+
13
+ - Officially support Python 3.13 (:pr:`2319`).
14
+ - Drop support for Python 3.8 (:pr:`2318`).
15
+
4
16
  3.22.0 (2024-08-20)
5
17
  *******************
6
18
 
@@ -1,31 +1,30 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: marshmallow
3
- Version: 3.22.0
3
+ Version: 3.23.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>
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
26
  Requires-Dist: autodocsumm==0.2.13 ; 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/bShdJw7z>`_ 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/bShdJw7z
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
@@ -111,7 +123,7 @@ Full documentation is available at https://marshmallow.readthedocs.io/ .
111
123
  Requirements
112
124
  ============
113
125
 
114
- - Python >= 3.8
126
+ - Python >= 3.9
115
127
 
116
128
  Ecosystem
117
129
  =========
@@ -22,6 +22,19 @@ marshmallow: simplified object serialization
22
22
 
23
23
  **marshmallow** is an ORM/ODM/framework-agnostic library for converting complex datatypes, such as objects, to and from native Python datatypes.
24
24
 
25
+ Sponsor Message
26
+ ===============
27
+
28
+ Input an OpenAPI spec to generate API docs that look as good as Stripe's. `Request a preview <https://form.typeform.com/to/bShdJw7z>`_ of your docs on Fern.
29
+
30
+ .. image:: https://github.com/user-attachments/assets/69916225-0d61-4bd7-b3b9-e378557673cb
31
+ :target: https://form.typeform.com/to/bShdJw7z
32
+ :align: center
33
+ :alt: Fern logo
34
+
35
+ Example
36
+ =======
37
+
25
38
  .. code-block:: python
26
39
 
27
40
  from datetime import date
@@ -73,7 +86,7 @@ Full documentation is available at https://marshmallow.readthedocs.io/ .
73
86
  Requirements
74
87
  ============
75
88
 
76
- - Python >= 3.8
89
+ - Python >= 3.9
77
90
 
78
91
  Ecosystem
79
92
  =========
@@ -0,0 +1,15 @@
1
+ /* Override alabaster's admonition styling, which we used for sponsored messages */
2
+
3
+ div.admonition-sponsor-message p.admonition-title {
4
+ font-size: 18px;
5
+ font-style: normal;
6
+ }
7
+
8
+ p.admonition-title::after {
9
+ content: "";
10
+ }
11
+
12
+ div.admonition-sponsor-message p {
13
+ font-size: 14px;
14
+ font-style: italic;
15
+ }
@@ -36,7 +36,7 @@ exclude_patterns = ["_build"]
36
36
  html_theme_path = [alabaster.get_path()]
37
37
  html_theme = "alabaster"
38
38
  html_static_path = ["_static"]
39
- html_css_files = ["css/versionwarning.css"]
39
+ html_css_files = ["css/versionwarning.css", "css/sponsor-message.css"]
40
40
  templates_path = ["_templates"]
41
41
  html_show_sourcelink = False
42
42
 
@@ -6,6 +6,15 @@ marshmallow: simplified object serialization
6
6
 
7
7
  Release v\ |version|. (:doc:`Changelog <changelog>`)
8
8
 
9
+ .. admonition:: Sponsor Message
10
+
11
+ Input an OpenAPI spec to generate API docs that look as good as Stripe's. `Request a preview <https://form.typeform.com/to/bShdJw7z>`_ of your docs on Fern.
12
+
13
+ .. image:: https://github.com/user-attachments/assets/69916225-0d61-4bd7-b3b9-e378557673cb
14
+ :target: https://form.typeform.com/to/bShdJw7z
15
+ :align: center
16
+ :alt: Fern logo
17
+
9
18
  .. include:: about.rst.inc
10
19
 
11
20
  Upgrading from an older version?
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "marshmallow"
3
- version = "3.22.0"
3
+ version = "3.23.0"
4
4
  description = "A lightweight library for converting complex datatypes to and from native Python datatypes."
5
5
  readme = "README.rst"
6
6
  license = { file = "LICENSE" }
@@ -15,13 +15,13 @@ classifiers = [
15
15
  "Intended Audience :: Developers",
16
16
  "License :: OSI Approved :: MIT License",
17
17
  "Programming Language :: Python :: 3",
18
- "Programming Language :: Python :: 3.8",
19
18
  "Programming Language :: Python :: 3.9",
20
19
  "Programming Language :: Python :: 3.10",
21
20
  "Programming Language :: Python :: 3.11",
22
21
  "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
23
  ]
24
- requires-python = ">=3.8"
24
+ requires-python = ">=3.9"
25
25
  dependencies = ["packaging>=17.0"]
26
26
 
27
27
  [project.urls]
@@ -33,14 +33,14 @@ Tidelift = "https://tidelift.com/subscription/pkg/pypi-marshmallow?utm_source=py
33
33
 
34
34
  [project.optional-dependencies]
35
35
  docs = [
36
- "sphinx==8.0.2",
37
- "sphinx-issues==4.1.0",
36
+ "sphinx==8.1.3",
37
+ "sphinx-issues==5.0.0",
38
38
  "alabaster==1.0.0",
39
39
  "sphinx-version-warning==1.1.2",
40
40
  "autodocsumm==0.2.13",
41
41
  ]
42
- tests = ["pytest", "pytz", "simplejson"]
43
- dev = ["marshmallow[tests]", "tox", "pre-commit~=3.5"]
42
+ tests = ["pytest", "simplejson"]
43
+ dev = ["marshmallow[tests]", "tox", "pre-commit>=3.5,<5.0"]
44
44
 
45
45
  [build-system]
46
46
  requires = ["flit_core<4"]
@@ -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>
@@ -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)
@@ -1878,7 +1882,7 @@ class Enum(Field):
1878
1882
  self,
1879
1883
  enum: type[EnumType],
1880
1884
  *,
1881
- by_value: bool | Field | type = False,
1885
+ by_value: bool | Field | type[Field] = False,
1882
1886
  **kwargs,
1883
1887
  ):
1884
1888
  super().__init__(**kwargs)
@@ -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 #####
@@ -4,14 +4,14 @@ import datetime as dt
4
4
  import functools
5
5
  import uuid
6
6
  from enum import Enum, IntEnum
7
+ from zoneinfo import ZoneInfo
7
8
 
8
- import pytz
9
9
  import simplejson
10
10
 
11
11
  from marshmallow import Schema, fields, missing, post_load, validate
12
12
  from marshmallow.exceptions import ValidationError
13
13
 
14
- central = pytz.timezone("America/Chicago")
14
+ central = ZoneInfo("America/Chicago")
15
15
 
16
16
 
17
17
  class GenderEnum(IntEnum):
@@ -104,9 +104,7 @@ class User:
104
104
  # A naive datetime
105
105
  self.created = dt.datetime(2013, 11, 10, 14, 20, 58)
106
106
  # A TZ-aware datetime
107
- self.updated = central.localize(
108
- dt.datetime(2013, 11, 10, 14, 20, 58), is_dst=False
109
- )
107
+ self.updated = dt.datetime(2013, 11, 10, 14, 20, 58, tzinfo=central)
110
108
  self.id = id_
111
109
  self.homepage = homepage
112
110
  self.email = email
@@ -477,7 +477,7 @@ class TestFieldDeserialization:
477
477
  ),
478
478
  (
479
479
  "Sun, 10 Nov 2013 01:23:45 -0600",
480
- central.localize(dt.datetime(2013, 11, 10, 1, 23, 45), is_dst=False),
480
+ dt.datetime(2013, 11, 10, 1, 23, 45, tzinfo=central),
481
481
  True,
482
482
  ),
483
483
  ],
@@ -521,7 +521,7 @@ class TestFieldDeserialization:
521
521
  ),
522
522
  (
523
523
  "2013-11-10T01:23:45-06:00",
524
- central.localize(dt.datetime(2013, 11, 10, 1, 23, 45), is_dst=False),
524
+ dt.datetime(2013, 11, 10, 1, 23, 45, tzinfo=central),
525
525
  True,
526
526
  ),
527
527
  ],
@@ -565,7 +565,7 @@ class TestFieldSerialization:
565
565
  "Sun, 10 Nov 2013 01:23:45 +0000",
566
566
  ),
567
567
  (
568
- central.localize(dt.datetime(2013, 11, 10, 1, 23, 45), is_dst=False),
568
+ dt.datetime(2013, 11, 10, 1, 23, 45, tzinfo=central),
569
569
  "Sun, 10 Nov 2013 01:23:45 -0600",
570
570
  ),
571
571
  ],
@@ -586,7 +586,7 @@ class TestFieldSerialization:
586
586
  ),
587
587
  (
588
588
  "timestamp",
589
- central.localize(dt.datetime(2013, 11, 10, 0, 23, 45), is_dst=False),
589
+ dt.datetime(2013, 11, 10, 0, 23, 45, tzinfo=central),
590
590
  1384064625,
591
591
  ),
592
592
  ("timestamp_ms", dt.datetime(2013, 11, 10, 0, 23, 45), 1384043025000),
@@ -597,7 +597,7 @@ class TestFieldSerialization:
597
597
  ),
598
598
  (
599
599
  "timestamp_ms",
600
- central.localize(dt.datetime(2013, 11, 10, 0, 23, 45), is_dst=False),
600
+ dt.datetime(2013, 11, 10, 0, 23, 45, tzinfo=central),
601
601
  1384064625000,
602
602
  ),
603
603
  ],
@@ -620,7 +620,7 @@ class TestFieldSerialization:
620
620
  "2013-11-10T01:23:45+00:00",
621
621
  ),
622
622
  (
623
- central.localize(dt.datetime(2013, 11, 10, 1, 23, 45), is_dst=False),
623
+ dt.datetime(2013, 11, 10, 1, 23, 45, tzinfo=central),
624
624
  "2013-11-10T01:23:45-06:00",
625
625
  ),
626
626
  ],
@@ -124,7 +124,7 @@ def test_is_collection():
124
124
  "Sun, 10 Nov 2013 01:23:45 +0000",
125
125
  ),
126
126
  (
127
- central.localize(dt.datetime(2013, 11, 10, 1, 23, 45), is_dst=False),
127
+ dt.datetime(2013, 11, 10, 1, 23, 45, tzinfo=central),
128
128
  "Sun, 10 Nov 2013 01:23:45 -0600",
129
129
  ),
130
130
  ],
@@ -146,7 +146,7 @@ def test_rfc_format(value, expected):
146
146
  "2013-11-10T01:23:45+00:00",
147
147
  ),
148
148
  (
149
- central.localize(dt.datetime(2013, 11, 10, 1, 23, 45), is_dst=False),
149
+ dt.datetime(2013, 11, 10, 1, 23, 45, tzinfo=central),
150
150
  "2013-11-10T01:23:45-06:00",
151
151
  ),
152
152
  ],
@@ -165,7 +165,7 @@ def test_isoformat(value, expected):
165
165
  ),
166
166
  (
167
167
  "Sun, 10 Nov 2013 01:23:45 -0600",
168
- central.localize(dt.datetime(2013, 11, 10, 1, 23, 45), is_dst=False),
168
+ dt.datetime(2013, 11, 10, 1, 23, 45, tzinfo=central),
169
169
  ),
170
170
  ],
171
171
  )
@@ -194,7 +194,7 @@ def test_from_rfc(value, expected):
194
194
  ),
195
195
  (
196
196
  "2013-11-10T01:23:45-06:00",
197
- central.localize(dt.datetime(2013, 11, 10, 1, 23, 45), is_dst=False),
197
+ dt.datetime(2013, 11, 10, 1, 23, 45, tzinfo=central),
198
198
  ),
199
199
  ],
200
200
  )
@@ -1,5 +1,5 @@
1
1
  [tox]
2
- envlist = lint,mypy-test,py{38,39,310,311,312},docs
2
+ envlist = lint,mypy-test,py{39,310,311,312,313},docs
3
3
 
4
4
  [testenv]
5
5
  extras = tests
File without changes
File without changes
File without changes
File without changes