Show More
@@ -194,9 +194,8 b' def json_clean(obj):' | |||||
194 | >>> json_clean(True) |
|
194 | >>> json_clean(True) | |
195 | True |
|
195 | True | |
196 | """ |
|
196 | """ | |
197 |
# types that are 'atomic' and ok in json as-is. |
|
197 | # types that are 'atomic' and ok in json as-is. | |
198 | # listed explicitly because bools pass as int instances |
|
198 | atomic_ok = (unicode_type, type(None)) | |
199 | atomic_ok = (unicode_type, int, type(None)) |
|
|||
200 |
|
199 | |||
201 | # containers that we need to convert into lists |
|
200 | # containers that we need to convert into lists | |
202 | container_to_list = (tuple, set, types.GeneratorType) |
|
201 | container_to_list = (tuple, set, types.GeneratorType) | |
@@ -205,7 +204,14 b' def json_clean(obj):' | |||||
205 | # cast out-of-range floats to their reprs |
|
204 | # cast out-of-range floats to their reprs | |
206 | if math.isnan(obj) or math.isinf(obj): |
|
205 | if math.isnan(obj) or math.isinf(obj): | |
207 | return repr(obj) |
|
206 | return repr(obj) | |
|
207 | return float(obj) | |||
|
208 | ||||
|
209 | if isinstance(obj, int): | |||
|
210 | # cast int to int, in case subclasses override __str__ (e.g. boost enum, #4598) | |||
|
211 | if isinstance(obj, bool): | |||
|
212 | # bools are ints, but we don't want to cast them to 0,1 | |||
208 | return obj |
|
213 | return obj | |
|
214 | return int(obj) | |||
209 |
|
215 | |||
210 | if isinstance(obj, atomic_ok): |
|
216 | if isinstance(obj, atomic_ok): | |
211 | return obj |
|
217 | return obj |
General Comments 0
You need to be logged in to leave comments.
Login now