<br><br><div class="gmail_quote">2011/10/27 Chris Rebert <span dir="ltr"><<a href="mailto:clp2@rebertia.com">clp2@rebertia.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Wed, Oct 26, 2011 at 2:14 AM, Amirouche Boubekki<br>
<<a href="mailto:amirouche.boubekki@gmail.com">amirouche.boubekki@gmail.com</a>> wrote:<br>
> Héllo,<br>
><br>
> I would like to fork simplejson [1] and implement serialization rules based<br>
> on protocols instead of types [2], plus special cases for protocol free<br>
> objects, that breaks compatibility. The benefit will be a better API for<br>
> json serialization of custom classes and in the case of iterable it will<br>
> avoid a calls like:<br>
><br>
>>>> simplejson.dumps(list(my_iterable))<br>
><br>
> The serialization of custom objects is documented in the class instead of<br>
> the ``default`` function of current simplejson implementation [3].<br>
><br>
> The encoding algorithm works with a priority list that is summarized in the<br>
> next table:<br>
><br>
> +-------------------+---------------+<br>
> | Python protocol | JSON |<br>
> | or special case | |<br>
> +===================+===============+<br>
</div><snip><br>
<div class="im">> | (§) unicode | see (§) |<br>
</div><snip><br>
<div class="im">> (§) if the algorithm arrives here, call unicode (with proper encoding rule)<br>
> on the object and use the result as json serialization<br>
<br>
</div>I would prefer a TypeError in such cases, for the same reason<br>
str.join() doesn't do an implicit str() on its operands:<br>
- Explicit is better than implicit.<br>
- (Likely) errors should never pass silently.<br>
- In the face of ambiguity, refuse the temptation to guess.<br></blockquote><div><br>granted it's better.<br></div></div><br>