serialite 0.3.4__tar.gz → 0.3.6__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 (35) hide show
  1. {serialite-0.3.4 → serialite-0.3.6}/PKG-INFO +13 -15
  2. {serialite-0.3.4 → serialite-0.3.6}/pyproject.toml +47 -33
  3. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_dispatcher.py +33 -23
  4. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_implementations/_tuple.py +3 -2
  5. serialite-0.3.4/LICENSE +0 -19
  6. {serialite-0.3.4 → serialite-0.3.6}/README.md +0 -0
  7. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/__init__.py +0 -0
  8. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_base.py +0 -0
  9. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_dataclass.py +0 -0
  10. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_decorators.py +0 -0
  11. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_descriptors.py +0 -0
  12. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_fields_serializer.py +0 -0
  13. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_implementations/__init__.py +0 -0
  14. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_implementations/_array.py +0 -0
  15. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_implementations/_boolean.py +0 -0
  16. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_implementations/_date_time.py +0 -0
  17. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_implementations/_dictionary.py +0 -0
  18. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_implementations/_float.py +0 -0
  19. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_implementations/_integer.py +0 -0
  20. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_implementations/_json.py +0 -0
  21. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_implementations/_list.py +0 -0
  22. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_implementations/_literal.py +0 -0
  23. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_implementations/_none.py +0 -0
  24. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_implementations/_ordered_set.py +0 -0
  25. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_implementations/_path.py +0 -0
  26. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_implementations/_reserved.py +0 -0
  27. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_implementations/_set.py +0 -0
  28. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_implementations/_string.py +0 -0
  29. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_implementations/_union.py +0 -0
  30. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_implementations/_uuid.py +0 -0
  31. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_mixins.py +0 -0
  32. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_monkey_patches.py +0 -0
  33. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_numeric_check.py +0 -0
  34. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_result.py +0 -0
  35. {serialite-0.3.4 → serialite-0.3.6}/src/serialite/_stable_set.py +0 -0
@@ -1,30 +1,29 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: serialite
3
- Version: 0.3.4
3
+ Version: 0.3.6
4
4
  Summary: A serialization library for Python
5
- Home-page: https://github.com/drhagen/serialite
6
- License: MIT
7
5
  Keywords: serialization,deserialization,serde,pydantic,fastapi
8
6
  Author: David Hagen
9
- Author-email: david@drhagen.com
10
- Requires-Python: >=3.10,<4.0
7
+ Author-email: David Hagen <david@drhagen.com>
8
+ License-Expression: MIT
11
9
  Classifier: Development Status :: 4 - Beta
12
10
  Classifier: Intended Audience :: Developers
13
11
  Classifier: License :: OSI Approved :: MIT License
14
12
  Classifier: Operating System :: OS Independent
15
13
  Classifier: Programming Language :: Python :: 3
16
- Classifier: Programming Language :: Python :: 3.10
17
- Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
18
16
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Requires-Dist: typing-extensions~=4.3
18
+ Requires-Dist: fastapi>=0.100,<0.111 ; extra == 'fastapi'
19
+ Requires-Dist: pydantic~=1.10 ; extra == 'fastapi'
20
+ Requires-Dist: numpy>=1.25,<2 ; extra == 'numpy'
21
+ Requires-Dist: ordered-set~=4.1 ; extra == 'ordered-set'
22
+ Requires-Python: >=3.12
23
+ Project-URL: Repository, https://github.com/drhagen/serialite
19
24
  Provides-Extra: fastapi
20
25
  Provides-Extra: numpy
21
26
  Provides-Extra: ordered-set
22
- Requires-Dist: fastapi (>=0.100,<0.111) ; extra == "fastapi"
23
- Requires-Dist: numpy (>=1.25,<2.0) ; (python_version < "3.13") and (extra == "numpy")
24
- Requires-Dist: ordered-set (>=4.1,<5.0) ; extra == "ordered-set"
25
- Requires-Dist: pydantic (>=1.10,<2.0) ; extra == "fastapi"
26
- Requires-Dist: typing_extensions (>=4.3,<5.0)
27
- Project-URL: Repository, https://github.com/drhagen/serialite
28
27
  Description-Content-Type: text/markdown
29
28
 
30
29
  # Serialite
@@ -67,4 +66,3 @@ Finding the correct serializer for each type can be a pain, so
67
66
  `serializer(cls: type) -> Serializer` is provided as a convenience function. This is a single
68
67
  dispatch function, which looks up the serializer registered for a particular type. For example,
69
68
  `serializer(list[float])` will return `ListSerializer(FloatSerializer)`.
70
-
@@ -1,48 +1,69 @@
1
- [tool.poetry]
1
+ [build-system]
2
+ requires = ["uv_build == 0.8.*"]
3
+ build-backend = "uv_build"
4
+
5
+ [project]
2
6
  name = "serialite"
3
- version = "0.3.4"
7
+ version = "0.3.6"
4
8
  description = "A serialization library for Python"
5
- authors = ["David Hagen <david@drhagen.com>"]
9
+ authors = [ { name = "David Hagen", email = "david@drhagen.com" } ]
6
10
  license = "MIT"
7
11
  readme = "README.md"
8
- repository = "https://github.com/drhagen/serialite"
9
12
  keywords = ["serialization", "deserialization", "serde", "pydantic", "fastapi"]
13
+ requires-python = ">=3.12"
10
14
  classifiers = [
11
15
  "Development Status :: 4 - Beta",
12
16
  "Intended Audience :: Developers",
13
- "Topic :: Software Development :: Libraries :: Python Modules",
17
+ "License :: OSI Approved :: MIT License",
14
18
  "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Topic :: Software Development :: Libraries :: Python Modules",
15
23
  ]
16
24
 
25
+ dependencies = [
26
+ "typing_extensions ~= 4.3",
27
+ ]
17
28
 
18
- [tool.poetry.dependencies]
19
- python = "^3.10"
20
- typing_extensions = "^4.3"
21
- fastapi = { version = ">=0.100,<0.111", optional = true }
22
- pydantic = { version = "^1.10", optional = true }
23
- ordered-set = { version = "^4.1", optional = true }
24
- # Lie about numpy only being needed below 3.13 in order to satisfy its Python ceiling
25
- numpy = { version = "^1.25", optional = true, python = "<3.13" }
29
+ [project.optional-dependencies]
30
+ fastapi = [
31
+ "fastapi >=0.100,<0.111",
32
+ "pydantic ~= 1.10",
33
+ ]
26
34
 
27
- [tool.poetry.dev-dependencies]
28
- nox_poetry = "^1.0.3"
35
+ numpy = [
36
+ "numpy >=1.25,<2",
37
+ ]
29
38
 
30
- # Test
31
- pytest = "^8"
32
- pytest-cov = "*"
33
- httpx = "*" # Needed by starlette testclient
39
+ ordered-set = [
40
+ "ordered-set ~= 4.1",
41
+ ]
34
42
 
35
- # Lint
36
- ruff = "^0.3"
43
+ [project.urls]
44
+ Repository = "https://github.com/drhagen/serialite"
37
45
 
38
- [tool.poetry.extras]
39
- fastapi = ["fastapi", "pydantic"]
40
- numpy = ["numpy"]
41
- ordered-set = ["ordered-set"]
46
+ [dependency-groups]
47
+ nox = [
48
+ "nox-uv == 0.6.*",
49
+ ]
50
+ test = [
51
+ "pytest == 8.*",
52
+ "coverage == 7.*",
53
+ "httpx", # Needed by starlette testclient
54
+ ]
55
+ lint = [
56
+ "ruff == 0.3.*"
57
+ ]
42
58
 
59
+ [tool.uv]
60
+ default-groups = "all"
61
+ python-preference = "only-managed"
43
62
 
44
63
  [tool.coverage.run]
45
64
  branch = true
65
+ source_pkgs = ["serialite"]
66
+ relative_files = true
46
67
 
47
68
  [tool.coverage.report]
48
69
  exclude_lines = [
@@ -54,11 +75,9 @@ exclude_lines = [
54
75
  [tool.coverage.paths]
55
76
  source = [
56
77
  "src/",
57
- ".nox/test*/lib/python*/site-packages/",
58
- ".nox/test*/Lib/site-packages/",
78
+ "**/site-packages/",
59
79
  ]
60
80
 
61
-
62
81
  [tool.ruff]
63
82
  src = ["src"]
64
83
  line-length = 99
@@ -92,8 +111,3 @@ classmethod-decorators = ["serialite._descriptors.classproperty"]
92
111
 
93
112
  [tool.ruff.lint.flake8-bugbear]
94
113
  extend-immutable-calls = ["serialite.field", "fastapi.Body"]
95
-
96
-
97
- [build-system]
98
- requires = ["poetry-core>=1.0.0"]
99
- build-backend = "poetry.core.masonry.api"
@@ -4,7 +4,7 @@ from abc import get_cache_token
4
4
  from datetime import datetime
5
5
  from pathlib import Path
6
6
  from types import GenericAlias, UnionType
7
- from typing import Any, Literal, TypeVar, Union, get_origin
7
+ from typing import Any, Literal, TypeAliasType, TypeVar, Union, get_origin
8
8
  from uuid import UUID
9
9
 
10
10
  from ._base import Serializer
@@ -67,6 +67,10 @@ def subclassdispatch(func):
67
67
  dispatch_cache.clear()
68
68
  cache_token = current_token
69
69
 
70
+ if isinstance(cls, TypeAliasType):
71
+ # Hash is not defined on TypeAliasType, so it cannot be used in WeakKeyDictionary
72
+ return type_alias_type_serializer
73
+
70
74
  origin = get_origin(cls)
71
75
  if origin in {Union, UnionType}:
72
76
  # issubclass does not work on Union and Optional
@@ -74,10 +78,10 @@ def subclassdispatch(func):
74
78
  # must bypass the dispatcher
75
79
  if len(cls.__args__) == 2 and cls.__args__[1] is type(None):
76
80
  # Optional is just a Union with NoneType in the second argument
77
- return optional_to_data
81
+ return optional_serializer
78
82
  else:
79
83
  # This is the standard Union
80
- return union_to_data
84
+ return union_serializer
81
85
 
82
86
  try:
83
87
  impl = dispatch_cache[cls]
@@ -90,13 +94,13 @@ def subclassdispatch(func):
90
94
  # must extract the base class and dispatch on that
91
95
  if origin is Literal:
92
96
  # issubclass does not work on Literal either
93
- impl = literal_to_data
97
+ impl = literal_serializer
94
98
  else:
95
99
  # This is the standard Generic class
96
100
  impl = _find_impl(origin, registry)
97
101
  elif cls is Any:
98
102
  # issubclass does not work on Any; must directly inject this
99
- impl = any_to_data
103
+ impl = any_serializer
100
104
  else:
101
105
  impl = _find_impl(cls, registry)
102
106
  dispatch_cache[cls] = impl
@@ -141,77 +145,77 @@ def serializer(cls: type[Output]) -> Serializer[Output]:
141
145
 
142
146
 
143
147
  @serializer.register(type(None))
144
- def none_to_data(cls):
148
+ def none_serializer(cls):
145
149
  from ._implementations import NoneSerializer
146
150
 
147
151
  return NoneSerializer()
148
152
 
149
153
 
150
154
  @serializer.register(bool)
151
- def boolean_to_data(cls):
155
+ def boolean_serializer(cls):
152
156
  from ._implementations import BooleanSerializer
153
157
 
154
158
  return BooleanSerializer()
155
159
 
156
160
 
157
161
  @serializer.register(int)
158
- def integer_to_data(cls):
162
+ def integer_serializer(cls):
159
163
  from ._implementations import IntegerSerializer
160
164
 
161
165
  return IntegerSerializer()
162
166
 
163
167
 
164
168
  @serializer.register(float)
165
- def float_to_data(cls):
169
+ def float_serializer(cls):
166
170
  from ._implementations import FloatSerializer
167
171
 
168
172
  return FloatSerializer()
169
173
 
170
174
 
171
175
  @serializer.register(str)
172
- def string_to_data(cls):
176
+ def string_serializer(cls):
173
177
  from ._implementations import StringSerializer
174
178
 
175
179
  return StringSerializer()
176
180
 
177
181
 
178
182
  @serializer.register(datetime)
179
- def datetime_to_data(cls):
183
+ def datetime_serializer(cls):
180
184
  from ._implementations import DateTimeSerializer
181
185
 
182
186
  return DateTimeSerializer()
183
187
 
184
188
 
185
189
  @serializer.register(UUID)
186
- def uuid_to_data(cls):
190
+ def uuid_serializer(cls):
187
191
  from ._implementations import UuidSerializer
188
192
 
189
193
  return UuidSerializer()
190
194
 
191
195
 
192
196
  @serializer.register(list)
193
- def list_to_data(cls):
197
+ def list_serializer(cls):
194
198
  from ._implementations import ListSerializer
195
199
 
196
200
  return ListSerializer(serializer(cls.__args__[0]))
197
201
 
198
202
 
199
203
  @serializer.register(set)
200
- def set_to_data(cls):
204
+ def set_serializer(cls):
201
205
  from ._implementations import SetSerializer
202
206
 
203
207
  return SetSerializer(serializer(cls.__args__[0]))
204
208
 
205
209
 
206
210
  @serializer.register(tuple)
207
- def tuple_to_data(cls):
211
+ def tuple_serializer(cls):
208
212
  from ._implementations import TupleSerializer
209
213
 
210
214
  return TupleSerializer(*(serializer(arg) for arg in cls.__args__))
211
215
 
212
216
 
213
217
  @serializer.register(dict)
214
- def dict_to_data(cls):
218
+ def dict_serializer(cls):
215
219
  from ._implementations import OrderedDictSerializer, RawDictSerializer
216
220
 
217
221
  if cls.__args__[0] is str:
@@ -221,7 +225,7 @@ def dict_to_data(cls):
221
225
 
222
226
 
223
227
  @serializer.register(Path)
224
- def path_to_data(cls):
228
+ def path_serializer(cls):
225
229
  from ._implementations import PathSerializer
226
230
 
227
231
  return PathSerializer()
@@ -229,7 +233,7 @@ def path_to_data(cls):
229
233
 
230
234
  # Union disables subclassing so Optional cannot be used to dispatch
231
235
  # @serializer.register(Optional)
232
- def optional_to_data(cls):
236
+ def optional_serializer(cls):
233
237
  from ._implementations import OptionalSerializer
234
238
 
235
239
  return OptionalSerializer(serializer(cls.__args__[0]))
@@ -237,26 +241,32 @@ def optional_to_data(cls):
237
241
 
238
242
  # Union disables subclassing so it cannot be used to dispatch
239
243
  # @serializer.register(Union)
240
- def union_to_data(cls):
244
+ def union_serializer(cls):
241
245
  from ._implementations import TryUnionSerializer
242
246
 
243
247
  return TryUnionSerializer(*[serializer(type_arg) for type_arg in cls.__args__])
244
248
 
245
249
 
246
250
  # @serializer.register(Literal)
247
- def literal_to_data(cls):
251
+ def literal_serializer(cls):
248
252
  from ._implementations import LiteralSerializer
249
253
 
250
254
  return LiteralSerializer(*cls.__args__)
251
255
 
252
256
 
253
257
  # @serializer.register(Any)
254
- def any_to_data(cls):
258
+ def any_serializer(cls):
255
259
  from ._implementations import JsonSerializer
256
260
 
257
261
  return JsonSerializer()
258
262
 
259
263
 
264
+ # TypeAliasType does not implement hashing so it cannot be used to dispatch
265
+ # @serializer.register(TypeAliasType)
266
+ def type_alias_type_serializer(cls):
267
+ return serializer(cls.__value__)
268
+
269
+
260
270
  try:
261
271
  import numpy as np
262
272
  except ImportError:
@@ -264,7 +274,7 @@ except ImportError:
264
274
  else:
265
275
 
266
276
  @serializer.register(np.ndarray)
267
- def array_to_data(cls):
277
+ def array_serializer(cls):
268
278
  from ._implementations import ArraySerializer
269
279
 
270
280
  return ArraySerializer(dtype=float)
@@ -277,7 +287,7 @@ except ImportError:
277
287
  else:
278
288
 
279
289
  @serializer.register(OrderedSet)
280
- def ordered_set_to_data(cls):
290
+ def ordered_set_serializer(cls):
281
291
  from ._implementations import OrderedSetSerializer
282
292
 
283
293
  return OrderedSetSerializer(serializer(cls.__args__[0]))
@@ -35,7 +35,7 @@ class TupleSerializer(Generic[Unpack[TupleArguments]], Serializer[tuple[Unpack[T
35
35
  # Validate values
36
36
  errors = {}
37
37
  values = []
38
- for i, (item, serializer) in enumerate(zip(data, self.element_serializers)):
38
+ for i, (item, serializer) in enumerate(zip(data, self.element_serializers, strict=True)):
39
39
  value_or_error = serializer.from_data(item)
40
40
  if isinstance(value_or_error, DeserializationFailure):
41
41
  errors[str(i)] = value_or_error.error
@@ -57,7 +57,8 @@ class TupleSerializer(Generic[Unpack[TupleArguments]], Serializer[tuple[Unpack[T
57
57
  )
58
58
 
59
59
  return [
60
- serializer.to_data(item) for item, serializer in zip(value, self.element_serializers)
60
+ serializer.to_data(item)
61
+ for item, serializer in zip(value, self.element_serializers, strict=True)
61
62
  ]
62
63
 
63
64
  def collect_openapi_models(
serialite-0.3.4/LICENSE DELETED
@@ -1,19 +0,0 @@
1
- Copyright (c) 2022 David R Hagen
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in all
11
- copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- SOFTWARE.
File without changes