https://github.com/python/cpython/commit/647053fed182066d3b8c934fb0bf52ee48ff3911
commit: 647053fed182066d3b8c934fb0bf52ee48ff3911
branch: main
author: Jan Max Meyer <[email protected]>
committer: encukou <[email protected]>
date: 2024-02-28T14:54:12+01:00
summary:
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.
files:
M Doc/library/json.rst
M Lib/json/encoder.py
diff --git a/Doc/library/json.rst b/Doc/library/json.rst
index 0ce4b697145cb3..c82ff9dc325b4c 100644
--- a/Doc/library/json.rst
+++ b/Doc/library/json.rst
@@ -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)
diff --git a/Lib/json/encoder.py b/Lib/json/encoder.py
index 45f547741885a8..597849eca0524a 100644
--- a/Lib/json/encoder.py
+++ b/Lib/json/encoder.py
@@ -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__} '
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]