def serializable(arg=None, **kwargs):
 if isinstance(arg, FunctionType):
  decorator = True
  func = arg
  serialized_type = BaseType
 elif ((arg is None) or isinstance(arg, (BaseType, TypeMeta))):
  decorator = False
  serialized_type = (arg or kwargs.pop(u'type', BaseType))
 else:
  raise TypeError(u"The argument to 'serializable' must be a function or a type.")
 if isinstance(serialized_type, BaseType):
  serialized_type._set_export_level(kwargs.pop(u'export_level', None), kwargs.pop(u'serialize_when_none', None))
  for (name, value) in kwargs.items():
   setattr(serialized_type, name, value)
 else:
  serialized_type = serialized_type(**kwargs)
 if decorator:
  return Serializable(func, serialized_type)
 else:
  return partial(Serializable, type=serialized_type)

def serializable ( arg = None , ** kwargs ) : if isinstance ( arg , FunctionType ) : decorator = True func = arg serialized_type = BaseType elif ( ( arg is None ) or isinstance ( arg , ( BaseType , TypeMeta ) ) ) : decorator = False serialized_type = ( arg or kwargs . pop ( u'type' , BaseType ) ) else : raise TypeError ( u"The argument to 'serializable' must be a function or a type." ) if isinstance ( serialized_type , BaseType ) : serialized_type . _set_export_level ( kwargs . pop ( u'export_level' , None ) , kwargs . pop ( u'serialize_when_none' , None ) ) for ( name , value ) in kwargs . items ( ) : setattr ( serialized_type , name , value ) else : serialized_type = serialized_type ( ** kwargs ) if decorator : return Serializable ( func , serialized_type ) else : return partial ( Serializable , type = serialized_type )
a serializable is a way to define dynamic serializable fields that are derived from other fields .