]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] doc: Use super() in subclassed JSONEncoder examples (GH-115565) (GH-116047)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 28 Feb 2024 14:13:08 +0000 (15:13 +0100)
committerGitHub <noreply@github.com>
Wed, 28 Feb 2024 14:13:08 +0000 (14:13 +0000)
doc: Use super() in subclassed JSONEncoder examples (GH-115565)

Replace calls to `json.JSONEncoder.default(self, obj)`
by `super().default(obj)` within the examples of the documentation.
(cherry picked from commit 647053fed182066d3b8c934fb0bf52ee48ff3911)

Co-authored-by: Jan Max Meyer <jmm@phorward.de>
Doc/library/json.rst
Lib/json/encoder.py

index e234fe92bc9995e8dfdc0b5961ca282db6c57f9f..226d1c3dbfcf63ec5ec3332125908b0cb988d554 100644 (file)
@@ -95,7 +95,7 @@ Extending :class:`JSONEncoder`::
     ...         if isinstance(obj, complex):
     ...             return [obj.real, obj.imag]
     ...         # Let the base class default method raise the TypeError
-    ...         return json.JSONEncoder.default(self, obj)
+    ...         return super().default(obj)
     ...
     >>> json.dumps(2 + 1j, cls=ComplexEncoder)
     '[2.0, 1.0]'
@@ -493,7 +493,7 @@ Encoders and Decoders
             else:
                 return list(iterable)
             # Let the base class default method raise the TypeError
-            return json.JSONEncoder.default(self, o)
+            return super().default(o)
 
 
    .. method:: encode(o)
index 45f547741885a8649d2ce4265a3e04cc87e20db7..597849eca0524a33c3f495c6dd56baa94032a2d0 100644 (file)
@@ -174,7 +174,7 @@ class JSONEncoder(object):
                 else:
                     return list(iterable)
                 # Let the base class default method raise the TypeError
-                return JSONEncoder.default(self, o)
+                return super().default(o)
 
         """
         raise TypeError(f'Object of type {o.__class__.__name__} '