Message171363
| Author |
Justin.Lebar |
| Recipients |
Justin.Lebar, docs@python |
| Date |
2012年09月26日.21:40:41 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1348695643.05.0.172807817425.issue16057@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
The JSONEncoder documentation says we can implement our own encoder as:
>>> class ComplexEncoder(json.JSONEncoder):
... def default(self, obj):
... if isinstance(obj, complex):
... return [obj.real, obj.imag]
... return json.JSONEncoder.default(self, obj)
Later on, we give the following example of how to implement the default method in a subclass of json.JSONEncoder:
def default(self, o):
try:
iterable = iter(o)
except TypeError:
pass
else:
return list(iterable)
return JSONEncoder.default(self, o)
These are both incorrect, as a quick reading of the source will reveal. JSONEncoder.default() throws for all input values. We should s/JSONEncoder.default/JSONEncoder.encode/ here, I think. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2012年09月26日 21:40:43 | Justin.Lebar | set | recipients:
+ Justin.Lebar, docs@python |
| 2012年09月26日 21:40:43 | Justin.Lebar | set | messageid: <1348695643.05.0.172807817425.issue16057@psf.upfronthosting.co.za> |
| 2012年09月26日 21:40:42 | Justin.Lebar | link | issue16057 messages |
| 2012年09月26日 21:40:41 | Justin.Lebar | create |
|