Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package python-json5 for openSUSE:Factory 
checked in at 2022-09-25 15:35:29
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-json5 (Old)
 and      /work/SRC/openSUSE:Factory/.python-json5.new.2275 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "python-json5"

Sun Sep 25 15:35:29 2022 rev:7 rq:1005760 version:0.9.10

Changes:
--------
--- /work/SRC/openSUSE:Factory/python-json5/python-json5.changes        
2022-05-30 12:45:03.668479227 +0200
+++ /work/SRC/openSUSE:Factory/.python-json5.new.2275/python-json5.changes      
2022-09-25 15:35:55.947713885 +0200
@@ -1,0 +2,15 @@
+Sat Sep 24 10:54:29 UTC 2022 - Dirk M??ller <dmuel...@suse.com>
+
+- update to 0.9.10:
+  * Updated the //README.md to be clear that parsing arbitrary JS
+    code may not work.
+  * Fixed serialization for objects that subclass `int` or `float`:
+    Previously we would use the objects __str__ implementation, but
+    that might result in an illegal JSON5 value if the object had
+    customized __str__ to return something illegal. Instead,
+    we follow the lead of the `JSON` module and call `int.__repr__`
+    or `float.__repr__` directly.
+  * While I was at it, I added tests for dumps(-inf) and dumps(nan)
+    when those were supposed to be disallowed by `allow_nan=False`.
+
+-------------------------------------------------------------------

Old:
----
  pyjson5-0.9.8.tar.gz

New:
----
  pyjson5-0.9.10.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ python-json5.spec ++++++
--- /var/tmp/diff_new_pack.DVpAPS/_old  2022-09-25 15:35:56.407714993 +0200
+++ /var/tmp/diff_new_pack.DVpAPS/_new  2022-09-25 15:35:56.415715012 +0200
@@ -25,7 +25,7 @@
 
 %{?!python_module:%define python_module() python-%{**} python3-%{**}}
 Name:           python-json5
-Version:        0.9.8
+Version:        0.9.10
 Release:        0
 Summary:        A Python implementation of the JSON5 data format
 License:        Apache-2.0

++++++ pyjson5-0.9.8.tar.gz -> pyjson5-0.9.10.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pyjson5-0.9.8/README.md new/pyjson5-0.9.10/README.md
--- old/pyjson5-0.9.8/README.md 2022-05-09 03:47:03.000000000 +0200
+++ new/pyjson5-0.9.10/README.md        2022-08-18 23:16:02.000000000 +0200
@@ -31,6 +31,10 @@
 **SLOW**. It can be 1000-6000x slower than the C-optimized JSON module,
 and is 200x slower (or more) than the pure Python JSON module.
 
+**Please Note:** This library only handles JSON5 documents, it does not
+allow you to read arbitrary JavaScript. For example, bare integers can
+be legal object keys in JavaScript, but they aren't in JSON5.
+
 ## Known issues
 
 * Did I mention that it is **SLOW**?
@@ -57,6 +61,21 @@
 
 ## Version History / Release Notes
 
+* v0.9.10 (2022-08-18)
+    * [GitHub issue #58](https://github.com/dpranke/pyjson5/issues/58)
+      Updated the //README.md to be clear that parsing arbitrary JS
+      code may not work.
+    * Otherwise, no code changes.
+* v0.9.9 (2022-08-01)
+    * [GitHub issue #57](https://github.com/dpranke/pyjson5/issues/57)
+      Fixed serialization for objects that subclass `int` or `float`:
+      Previously we would use the objects __str__ implementation, but
+      that might result in an illegal JSON5 value if the object had
+      customized __str__ to return something illegal. Instead,
+      we follow the lead of the `JSON` module and call `int.__repr__`
+      or `float.__repr__` directly.
+    * While I was at it, I added tests for dumps(-inf) and dumps(nan)
+      when those were supposed to be disallowed by `allow_nan=False`.
 * v0.9.8 (2022-05-08)
     * [GitHub issue #47](https://github.com/dpranke/pyjson5/issues/47)
       Fixed error reporting in some cases due to how parsing was handling
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pyjson5-0.9.8/json5/lib.py 
new/pyjson5-0.9.10/json5/lib.py
--- old/pyjson5-0.9.8/json5/lib.py      2022-05-09 03:47:03.000000000 +0200
+++ new/pyjson5-0.9.10/json5/lib.py     2022-08-18 23:16:02.000000000 +0200
@@ -264,15 +264,36 @@
         s = u'false'
     elif obj is None:
         s = u'null'
+    elif obj == math.inf:
+        if allow_nan:
+            s = u'Infinity'
+        else:
+            raise ValueError()
+    elif obj == -math.inf:
+        if allow_nan:
+            s = u'-Infinity'
+        else:
+            raise ValueError()
+    elif isinstance(obj, float) and math.isnan(obj):
+        if allow_nan:
+            s = u'NaN'
+        else:
+            raise ValueError()
     elif isinstance(obj, str_types):
         if (is_key and _is_ident(obj) and not quote_keys
             and not _is_reserved_word(obj)):
             return True, obj
         return True, _dump_str(obj, ensure_ascii)
-    elif isinstance(obj, float):
-        s = _dump_float(obj,allow_nan)
     elif isinstance(obj, int):
-        s = str(obj)
+        # Subclasses of `int` and `float` may have custom
+        # __repr__ or __str__ methods, but the `JSON` library
+        # ignores them in order to ensure that the representation
+        # are just bare numbers. In order to match JSON's behavior
+        # we call the methods of the `float` and `int` class directly.
+        s = int.__repr__(obj)
+    elif isinstance(obj, float):
+        # See comment above for int
+        s = float.__repr__(obj)
     else:
         s = None
 
@@ -403,20 +424,6 @@
             end_str + u']')
 
 
-def _dump_float(obj, allow_nan):
-    if allow_nan:
-        if math.isnan(obj):
-            return 'NaN'
-        if obj == float('inf'):
-            return 'Infinity'
-        if obj == float('-inf'):
-            return '-Infinity'
-    elif math.isnan(obj) or obj == float('inf') or obj == float('-inf'):
-        raise ValueError('Out of range float values '
-                         'are not JSON compliant')
-    return str(obj)
-
-
 def _dump_str(obj, ensure_ascii):
     ret = ['"']
     for ch in obj:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pyjson5-0.9.8/json5/version.py 
new/pyjson5-0.9.10/json5/version.py
--- old/pyjson5-0.9.8/json5/version.py  2022-05-09 03:47:03.000000000 +0200
+++ new/pyjson5-0.9.10/json5/version.py 2022-08-18 23:16:02.000000000 +0200
@@ -12,4 +12,4 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-VERSION = '0.9.8'
+VERSION = '0.9.10'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pyjson5-0.9.8/tests/lib_test.py 
new/pyjson5-0.9.10/tests/lib_test.py
--- old/pyjson5-0.9.8/tests/lib_test.py 2022-05-09 03:47:03.000000000 +0200
+++ new/pyjson5-0.9.10/tests/lib_test.py        2022-08-18 23:16:02.000000000 
+0200
@@ -347,13 +347,20 @@
         self.assertEqual(json5.dumps(MyArray()), '[0, 1, 1]')
 
     def test_custom_numbers(self):
+        # See https://github.com/dpranke/pyjson5/issues/57: we
+        # need to ensure that we use the bare int.__repr__ and
+        # float.__repr__ in order to get legal JSON values when
+        # people have custom subclasses with customer __repr__ methods.
+        # (This is what JSON does and we want to match it).
         class MyInt(int):
-            pass
+            def __repr__(self):
+                return 'fail'
 
         self.assertEqual(json5.dumps(MyInt(5)), '5')
 
         class MyFloat(float):
-            pass
+            def __repr__(self):
+                return 'fail'
 
         self.assertEqual(json5.dumps(MyFloat(0.5)), '0.5')
 
@@ -427,6 +434,10 @@
 
         self.assertRaises(ValueError, json5.dumps,
                           float('inf'), allow_nan=False)
+        self.assertRaises(ValueError, json5.dumps,
+                          float('-inf'), allow_nan=False)
+        self.assertRaises(ValueError, json5.dumps,
+                          float('nan'), allow_nan=False)
 
     def test_null(self):
         self.check(None, 'null')

Reply via email to