serializable 1.2.1__tar.gz → 1.3.1__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 (34) hide show
  1. serializable-1.3.1/MANIFEST.in +4 -0
  2. {serializable-1.2.1 → serializable-1.3.1}/PKG-INFO +4 -3
  3. {serializable-1.2.1 → serializable-1.3.1}/README.md +3 -0
  4. {serializable-1.2.1 → serializable-1.3.1}/pyproject.toml +1 -3
  5. {serializable-1.2.1 → serializable-1.3.1}/serializable/helpers.py +8 -3
  6. {serializable-1.2.1 → serializable-1.3.1}/serializable/version.py +1 -1
  7. {serializable-1.2.1 → serializable-1.3.1}/serializable.egg-info/PKG-INFO +4 -3
  8. {serializable-1.2.1 → serializable-1.3.1}/serializable.egg-info/SOURCES.txt +3 -1
  9. {serializable-1.2.1 → serializable-1.3.1}/serializable.egg-info/requires.txt +0 -2
  10. serializable-1.3.1/tests/__init__.py +0 -0
  11. serializable-1.3.1/tests/common.py +18 -0
  12. {serializable-1.2.1 → serializable-1.3.1}/tests/test_primitive_values.py +19 -1
  13. serializable-1.2.1/setup.py +0 -6
  14. {serializable-1.2.1 → serializable-1.3.1}/LICENSE +0 -0
  15. {serializable-1.2.1 → serializable-1.3.1}/serializable/__init__.py +0 -0
  16. {serializable-1.2.1 → serializable-1.3.1}/serializable/dataclass_serializable.py +0 -0
  17. {serializable-1.2.1 → serializable-1.3.1}/serializable/primitive_types.py +0 -0
  18. {serializable-1.2.1 → serializable-1.3.1}/serializable/py.typed +0 -0
  19. {serializable-1.2.1 → serializable-1.3.1}/serializable/serializable.py +0 -0
  20. {serializable-1.2.1 → serializable-1.3.1}/serializable.egg-info/dependency_links.txt +0 -0
  21. {serializable-1.2.1 → serializable-1.3.1}/serializable.egg-info/top_level.txt +0 -0
  22. {serializable-1.2.1 → serializable-1.3.1}/setup.cfg +0 -0
  23. {serializable-1.2.1 → serializable-1.3.1}/tests/test_class.py +0 -0
  24. {serializable-1.2.1 → serializable-1.3.1}/tests/test_dataclass_serializable.py +0 -0
  25. {serializable-1.2.1 → serializable-1.3.1}/tests/test_default_to_dict_implementation.py +0 -0
  26. {serializable-1.2.1 → serializable-1.3.1}/tests/test_function.py +0 -0
  27. {serializable-1.2.1 → serializable-1.3.1}/tests/test_keyword_aliases.py +0 -0
  28. {serializable-1.2.1 → serializable-1.3.1}/tests/test_namedtuple.py +0 -0
  29. {serializable-1.2.1 → serializable-1.3.1}/tests/test_nesting.py +0 -0
  30. {serializable-1.2.1 → serializable-1.3.1}/tests/test_object.py +0 -0
  31. {serializable-1.2.1 → serializable-1.3.1}/tests/test_pickle.py +0 -0
  32. {serializable-1.2.1 → serializable-1.3.1}/tests/test_set.py +0 -0
  33. {serializable-1.2.1 → serializable-1.3.1}/tests/test_tuple.py +0 -0
  34. {serializable-1.2.1 → serializable-1.3.1}/tests/test_typing.py +0 -0
@@ -0,0 +1,4 @@
1
+ # setuptools only adds tests/test*.py to the sdist by default; ship the whole
2
+ # suite (tests/__init__.py, tests/common.py) so tests run from the tarball.
3
+ graft tests
4
+ global-exclude *.py[cod]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: serializable
3
- Version: 1.2.1
3
+ Version: 1.3.1
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,13 +224,11 @@ 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"
231
230
  Requires-Dist: ruff; extra == "dev"
232
231
  Requires-Dist: mypy; extra == "dev"
233
- Requires-Dist: coveralls; extra == "dev"
234
232
  Requires-Dist: build; extra == "dev"
235
233
  Requires-Dist: twine; extra == "dev"
236
234
  Dynamic: license-file
@@ -292,6 +290,9 @@ If you change the keyword arguments to a class which derives from `Serializable`
292
290
  The format records Python classes and modules, which must remain importable when
293
291
  loading data. Keys starting with two underscores are reserved. Nested Python
294
292
  values require the serialization helpers rather than ordinary JSON encoding.
293
+ `to_json` raises `ValueError` for NaN or infinite floats, which standard JSON
294
+ can't represent; `from_json` still reads the `NaN` / `Infinity` literals which
295
+ older versions wrote.
295
296
 
296
297
  ## Documentation
297
298
 
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  [build-system]
2
- requires = ["setuptools>=61.0", "wheel"]
2
+ requires = ["setuptools>=64", "wheel"]
3
3
  build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
@@ -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]
@@ -38,7 +37,6 @@ dev = [
38
37
  "pytest-cov",
39
38
  "ruff",
40
39
  "mypy",
41
- "coveralls",
42
40
  "build",
43
41
  "twine",
44
42
  ]
@@ -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.1"
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.1
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,13 +224,11 @@ 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"
231
230
  Requires-Dist: ruff; extra == "dev"
232
231
  Requires-Dist: mypy; extra == "dev"
233
- Requires-Dist: coveralls; extra == "dev"
234
232
  Requires-Dist: build; extra == "dev"
235
233
  Requires-Dist: twine; extra == "dev"
236
234
  Dynamic: license-file
@@ -292,6 +290,9 @@ If you change the keyword arguments to a class which derives from `Serializable`
292
290
  The format records Python classes and modules, which must remain importable when
293
291
  loading data. Keys starting with two underscores are reserved. Nested Python
294
292
  values require the serialization helpers rather than ordinary JSON encoding.
293
+ `to_json` raises `ValueError` for NaN or infinite floats, which standard JSON
294
+ can't represent; `from_json` still reads the `NaN` / `Infinity` literals which
295
+ older versions wrote.
295
296
 
296
297
  ## Documentation
297
298
 
@@ -1,7 +1,7 @@
1
1
  LICENSE
2
+ MANIFEST.in
2
3
  README.md
3
4
  pyproject.toml
4
- setup.py
5
5
  serializable/__init__.py
6
6
  serializable/dataclass_serializable.py
7
7
  serializable/helpers.py
@@ -14,6 +14,8 @@ serializable.egg-info/SOURCES.txt
14
14
  serializable.egg-info/dependency_links.txt
15
15
  serializable.egg-info/requires.txt
16
16
  serializable.egg-info/top_level.txt
17
+ tests/__init__.py
18
+ tests/common.py
17
19
  tests/test_class.py
18
20
  tests/test_dataclass_serializable.py
19
21
  tests/test_default_to_dict_implementation.py
@@ -1,11 +1,9 @@
1
1
  typechecks>=0.0.2
2
- simplejson>=3.0.0
3
2
 
4
3
  [dev]
5
4
  pytest
6
5
  pytest-cov
7
6
  ruff
8
7
  mypy
9
- coveralls
10
8
  build
11
9
  twine
File without changes
@@ -0,0 +1,18 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+
14
+ def eq_(x, y, s=None):
15
+ if s:
16
+ assert x == y, s
17
+ else:
18
+ assert x == y
@@ -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])
@@ -1,6 +0,0 @@
1
- from setuptools import setup
2
-
3
-
4
- if __name__ == "__main__":
5
- # Delegate metadata to pyproject.toml.
6
- setup()
File without changes
File without changes