Emitter construction should check for __emittable__ first

Issue #150 new
Alexis Petrounias
created an issue

If the internal //_any// method checks whether //thing// is //emittable// first, it is possible to provide custom serialization for classes which are instances of any of the other types //_any// checks for.

For example, if you want to serialize an //OrderedDict//, which inherits from //dict//, into a tuple list of //(key, value)//, the check //isinstance(thing, dict)// blocks any functionality provided by implementing //emittable//.

Comments (2)

  1. Alexis Petrounias reporter

    Yes, as long as "if hasattr(thing, 'emittable')" executes first, you can define your own serialization without affecting the defaults, or any other custom serialization. I am not sure what the default behavior should be if emittable is not callable or does not return; your proposed solution silently falls back to default serialization. This is a valid and probably acceptable behavior for many uses. Another valid behavior could be to raise an exception. Furthermore, an optional argument could indicate what the behavior in such circumstances should be.

  2. Log in to comment