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