mirror of
https://github.com/python/cpython.git
synced 2025-12-31 12:33:28 +00:00
[3.12] doc: Use super() in subclassed JSONEncoder examples (GH-115565) (GH-116047)
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 647053fed1)
Co-authored-by: Jan Max Meyer <jmm@phorward.de>
This commit is contained in:
parent
e5e98626a1
commit
9df6d1e033
2 changed files with 3 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ def default(self, o):
|
|||
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__} '
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue