serializable 1.2.1__tar.gz → 1.3.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 (31) hide show
  1. {serializable-1.2.1 → serializable-1.3.0}/PKG-INFO +4 -2
  2. {serializable-1.2.1 → serializable-1.3.0}/README.md +3 -0
  3. {serializable-1.2.1 → serializable-1.3.0}/pyproject.toml +0 -1
  4. {serializable-1.2.1 → serializable-1.3.0}/serializable/helpers.py +8 -3
  5. {serializable-1.2.1 → serializable-1.3.0}/serializable/version.py +1 -1
  6. {serializable-1.2.1 → serializable-1.3.0}/serializable.egg-info/PKG-INFO +4 -2
  7. {serializable-1.2.1 → serializable-1.3.0}/serializable.egg-info/requires.txt +0 -1
  8. {serializable-1.2.1 → serializable-1.3.0}/tests/test_primitive_values.py +19 -1
  9. {serializable-1.2.1 → serializable-1.3.0}/LICENSE +0 -0
  10. {serializable-1.2.1 → serializable-1.3.0}/serializable/__init__.py +0 -0
  11. {serializable-1.2.1 → serializable-1.3.0}/serializable/dataclass_serializable.py +0 -0
  12. {serializable-1.2.1 → serializable-1.3.0}/serializable/primitive_types.py +0 -0
  13. {serializable-1.2.1 → serializable-1.3.0}/serializable/py.typed +0 -0
  14. {serializable-1.2.1 → serializable-1.3.0}/serializable/serializable.py +0 -0
  15. {serializable-1.2.1 → serializable-1.3.0}/serializable.egg-info/SOURCES.txt +0 -0
  16. {serializable-1.2.1 → serializable-1.3.0}/serializable.egg-info/dependency_links.txt +0 -0
  17. {serializable-1.2.1 → serializable-1.3.0}/serializable.egg-info/top_level.txt +0 -0
  18. {serializable-1.2.1 → serializable-1.3.0}/setup.cfg +0 -0
  19. {serializable-1.2.1 → serializable-1.3.0}/setup.py +0 -0
  20. {serializable-1.2.1 → serializable-1.3.0}/tests/test_class.py +0 -0
  21. {serializable-1.2.1 → serializable-1.3.0}/tests/test_dataclass_serializable.py +0 -0
  22. {serializable-1.2.1 → serializable-1.3.0}/tests/test_default_to_dict_implementation.py +0 -0
  23. {serializable-1.2.1 → serializable-1.3.0}/tests/test_function.py +0 -0
  24. {serializable-1.2.1 → serializable-1.3.0}/tests/test_keyword_aliases.py +0 -0
  25. {serializable-1.2.1 → serializable-1.3.0}/tests/test_namedtuple.py +0 -0
  26. {serializable-1.2.1 → serializable-1.3.0}/tests/test_nesting.py +0 -0
  27. {serializable-1.2.1 → serializable-1.3.0}/tests/test_object.py +0 -0
  28. {serializable-1.2.1 → serializable-1.3.0}/tests/test_pickle.py +0 -0
  29. {serializable-1.2.1 → serializable-1.3.0}/tests/test_set.py +0 -0
  30. {serializable-1.2.1 → serializable-1.3.0}/tests/test_tuple.py +0 -0
  31. {serializable-1.2.1 → serializable-1.3.0}/tests/test_typing.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: serializable
3
- Version: 1.2.1
3
+ Version: 1.3.0
4
4
  Summary: Base class with serialization helpers for user-defined Python objects
5
5
  Author-email: Alex Rubinsteyn <alex.rubinsteyn@unc.edu>
6
6
  License: Apache License
@@ -224,7 +224,6 @@ Requires-Python: >=3.9
224
224
  Description-Content-Type: text/markdown
225
225
  License-File: LICENSE
226
226
  Requires-Dist: typechecks>=0.0.2
227
- Requires-Dist: simplejson>=3.0.0
228
227
  Provides-Extra: dev
229
228
  Requires-Dist: pytest; extra == "dev"
230
229
  Requires-Dist: pytest-cov; extra == "dev"
@@ -292,6 +291,9 @@ If you change the keyword arguments to a class which derives from `Serializable`
292
291
  The format records Python classes and modules, which must remain importable when
293
292
  loading data. Keys starting with two underscores are reserved. Nested Python
294
293
  values require the serialization helpers rather than ordinary JSON encoding.
294
+ `to_json` raises `ValueError` for NaN or infinite floats, which standard JSON
295
+ can't represent; `from_json` still reads the `NaN` / `Infinity` literals which
296
+ older versions wrote.
295
297
 
296
298
  ## Documentation
297
299
 
@@ -55,6 +55,9 @@ If you change the keyword arguments to a class which derives from `Serializable`
55
55
  The format records Python classes and modules, which must remain importable when
56
56
  loading data. Keys starting with two underscores are reserved. Nested Python
57
57
  values require the serialization helpers rather than ordinary JSON encoding.
58
+ `to_json` raises `ValueError` for NaN or infinite floats, which standard JSON
59
+ can't represent; `from_json` still reads the `NaN` / `Infinity` literals which
60
+ older versions wrote.
58
61
 
59
62
  ## Documentation
60
63
 
@@ -29,7 +29,6 @@ classifiers = [
29
29
  requires-python = ">=3.9"
30
30
  dependencies = [
31
31
  "typechecks>=0.0.2",
32
- "simplejson>=3.0.0",
33
32
  ]
34
33
 
35
34
  [project.optional-dependencies]
@@ -17,12 +17,11 @@ objects into serializable types.
17
17
 
18
18
  from __future__ import annotations
19
19
 
20
+ import json
20
21
  from functools import lru_cache
21
22
  from types import BuiltinFunctionType, FunctionType
22
23
  from typing import Any, Union
23
24
 
24
- import simplejson as json # type: ignore[import-untyped]
25
-
26
25
  from .primitive_types import PRIMITIVE_TYPES
27
26
 
28
27
 
@@ -310,13 +309,19 @@ def to_json(x: Any) -> str:
310
309
  """
311
310
  Returns JSON representation of a given Serializable instance or
312
311
  other primitive object.
312
+
313
+ Raises ValueError for NaN or infinite floats, which have no standard
314
+ JSON representation.
313
315
  """
314
- return json.dumps(to_serializable_repr(x))
316
+ return json.dumps(to_serializable_repr(x), allow_nan=False)
315
317
 
316
318
 
317
319
  def from_json(json_string: Union[str, bytes]) -> Any:
318
320
  """
319
321
  Inverse of to_json. Objects are reconstructed bottom-up while parsing,
320
322
  equivalent to (but faster than) from_serializable_repr(json.loads(...)).
323
+
324
+ Accepts the NaN and Infinity literals which older versions of
325
+ serializable wrote.
321
326
  """
322
327
  return json.loads(json_string, object_hook=_from_reconstructed_dict)
@@ -1,4 +1,4 @@
1
- __version__ = "1.2.1"
1
+ __version__ = "1.3.0"
2
2
 
3
3
 
4
4
  def print_version():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: serializable
3
- Version: 1.2.1
3
+ Version: 1.3.0
4
4
  Summary: Base class with serialization helpers for user-defined Python objects
5
5
  Author-email: Alex Rubinsteyn <alex.rubinsteyn@unc.edu>
6
6
  License: Apache License
@@ -224,7 +224,6 @@ Requires-Python: >=3.9
224
224
  Description-Content-Type: text/markdown
225
225
  License-File: LICENSE
226
226
  Requires-Dist: typechecks>=0.0.2
227
- Requires-Dist: simplejson>=3.0.0
228
227
  Provides-Extra: dev
229
228
  Requires-Dist: pytest; extra == "dev"
230
229
  Requires-Dist: pytest-cov; extra == "dev"
@@ -292,6 +291,9 @@ If you change the keyword arguments to a class which derives from `Serializable`
292
291
  The format records Python classes and modules, which must remain importable when
293
292
  loading data. Keys starting with two underscores are reserved. Nested Python
294
293
  values require the serialization helpers rather than ordinary JSON encoding.
294
+ `to_json` raises `ValueError` for NaN or infinite floats, which standard JSON
295
+ can't represent; `from_json` still reads the `NaN` / `Infinity` literals which
296
+ older versions wrote.
295
297
 
296
298
  ## Documentation
297
299
 
@@ -1,5 +1,4 @@
1
1
  typechecks>=0.0.2
2
- simplejson>=3.0.0
3
2
 
4
3
  [dev]
5
4
  pytest
@@ -10,7 +10,11 @@
10
10
  # See the License for the specific language governing permissions and
11
11
  # limitations under the License.
12
12
 
13
- from serializable import from_serializable_repr, to_serializable_repr
13
+ import math
14
+
15
+ import pytest
16
+
17
+ from serializable import from_json, from_serializable_repr, to_json, to_serializable_repr
14
18
 
15
19
  from .common import eq_
16
20
 
@@ -29,3 +33,17 @@ def test_bool():
29
33
 
30
34
  def test_str():
31
35
  eq_("waffles", from_serializable_repr(to_serializable_repr("waffles")))
36
+
37
+
38
+ @pytest.mark.parametrize("value", [math.nan, math.inf, -math.inf])
39
+ def test_to_json_rejects_non_finite_floats(value):
40
+ # NaN and infinities have no standard JSON representation
41
+ with pytest.raises(ValueError, match="Out of range float values"):
42
+ to_json([value])
43
+
44
+
45
+ def test_from_json_accepts_non_finite_literals():
46
+ # serializable used to write these (with simplejson < 3.19)
47
+ values = from_json("[NaN, Infinity, -Infinity]")
48
+ assert math.isnan(values[0])
49
+ eq_(values[1:], [math.inf, -math.inf])
File without changes
File without changes
File without changes