def coerce(from_, to, **to_kwargs):
 def preprocessor(func, argname, arg):
  if isinstance(arg, from_):
   return to(arg, **to_kwargs)
  return arg
 return preprocessor

def coerce ( from_ , to , ** to_kwargs ) : def preprocessor ( func , argname , arg ) : if isinstance ( arg , from_ ) : return to ( arg , ** to_kwargs ) return arg return preprocessor
a preprocessing decorator that coerces inputs of a given type by passing them to a callable .