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.
This commit is contained in:
Jan Max Meyer 2024-02-28 14:54:12 +01:00 committed by GitHub
parent 449c6da2bd
commit 647053fed1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View File

@ -106,7 +106,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]'
@ -504,7 +504,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)

View 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__} '