Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
dd246171
Commit
dd246171
authored
Mar 17, 2013
by
R David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#16057: Clarify why the base method default is called in custom encoders.
Original patch by Kushal Das.
parent
f3460414
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
0 deletions
+3
-0
Doc/library/json.rst
Doc/library/json.rst
+2
-0
Lib/json/encoder.py
Lib/json/encoder.py
+1
-0
No files found.
Doc/library/json.rst
View file @
dd246171
...
...
@@ -83,6 +83,7 @@ Extending :class:`JSONEncoder`::
... def default(self, obj):
... if isinstance(obj, complex):
... return [obj.real, obj.imag]
... # Let the base class default method raise the TypeError
... return json.JSONEncoder.default(self, obj)
...
>>> json.dumps(2 + 1j, cls=ComplexEncoder)
...
...
@@ -431,6 +432,7 @@ Encoders and Decoders
pass
else:
return list(iterable)
# Let the base class default method raise the TypeError
return json.JSONEncoder.default(self, o)
...
...
Lib/json/encoder.py
View file @
dd246171
...
...
@@ -166,6 +166,7 @@ class JSONEncoder(object):
pass
else
:
return
list
(
iterable
)
# Let the base class default method raise the TypeError
return
JSONEncoder
.
default
(
self
,
o
)
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment