Custom JSON encoder's default() doesn't call super() #44

Closed
erikrose opened this Issue Dec 13, 2012 · 0 comments

Comments

Projects
None yet
1 participant
@erikrose
Contributor

erikrose commented Dec 13, 2012

We should. Otherwise, we'll happily return None for unhandle-able values rather than raising TypeError.

@ghost ghost assigned erikrose Mar 19, 2013

erikrose added a commit that referenced this issue Mar 20, 2013

Make JSON encoder extension point clear, and call super() properly fr…
…om decoder. Remove from_python(). Fix #42, #44.

We move JsonEncoder out to the module level and transplant the guts of from_python into JsonEncoder.default(). This makes it possible to call super() from the decoder, which would be very awkward from from_python().

The way to make the decoder aware of new types is now to subclass our JsonEncoder and stick your new class into an ElasticSearch object's json_encoder attr.

We take advantage of the new design to call super() from the decoder, which leads us raise a TypeError on unexpected input, as is usual with the json module, rather than a ValueError or other error.

@erikrose erikrose closed this Mar 20, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment