]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add test for explicit `cls` argument bypassing default JSON decoder (#154094)
authorDominic H. <dom@dominic.sk>
Sun, 19 Jul 2026 11:58:06 +0000 (13:58 +0200)
committerGitHub <noreply@github.com>
Sun, 19 Jul 2026 11:58:06 +0000 (13:58 +0200)
* Add test for skipped `cls=None` case

* Fix lint

* Add new line between classes

Lib/test/test_json/test_decode.py

index 1d51fb2de0e69e4aa458724223f2561dddbea428..6d05ef8f8eb09181014737f56782fd94be90946f 100644 (file)
@@ -1,4 +1,5 @@
 import decimal
+import unittest.mock
 from io import StringIO
 from collections import OrderedDict
 from test.test_json import PyTest, CTest
@@ -155,6 +156,15 @@ class TestDecode:
             with self.assertRaises(ValueError):
                 self.loads('1' * (maxdigits + 1))
 
+    def test_explicit_cls_skips_json_decoder_default(self):
+        class CustomDecoder:
+            pass
+
+        with unittest.mock.patch.object(
+                CustomDecoder, 'decode', create=True) as mock_decode:
+            self.loads('{}', cls=CustomDecoder)
+        mock_decode.assert_called_once()
+
 
 class TestPyDecode(TestDecode, PyTest): pass
 class TestCDecode(TestDecode, CTest): pass