From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 28 Feb 2024 14:08:40 +0000 (+0100) Subject: [3.11] doc: Use super() in subclassed JSONEncoder examples (GH-115565) (GH-116046) X-Git-Tag: v3.11.9~132 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f2257402113b63c7d22af929d68918cae249402b;p=thirdparty%2FPython%2Fcpython.git [3.11] doc: Use super() in subclassed JSONEncoder examples (GH-115565) (GH-116046) 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 --- diff --git a/Doc/library/json.rst b/Doc/library/json.rst index e234fe92bc99..226d1c3dbfcf 100644 --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -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) diff --git a/Lib/json/encoder.py b/Lib/json/encoder.py index 45f547741885..597849eca052 100644 --- a/Lib/json/encoder.py +++ b/Lib/json/encoder.py @@ -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__} '