def init_subclass_by_name(baseclass, short_name, params):
sc = baseclass.__subclasses__()<EOL>for kls in sc:<EOL><INDENT>if kls.short_name == short_name or(_is_collection(kls.short_name) and short_name in kls.short_name):<EOL><INDENT>try:<EOL><INDENT>return kls(**params)<EOL><DEDENT>except TypeError as e:<EOL><INDENT>spec = inspect.getargspec(kls.__init__)<EOL>if '<STR_LIT>' in str(e):<EOL><INDENT>avail = join_quoted(spec.args[<NUM_LIT:1>:])<EOL>raise RuntimeError(<EOL>"<STR_LIT>"<EOL>% (short_name, str(e), avail))<EOL><DEDENT>elif '<STR_LIT>' in str(e):<EOL><INDENT>required = join_quoted(spec.args[<NUM_LIT:1>:-len(spec.defaults)])<EOL>raise RuntimeError(<EOL>"<STR_LIT>"<EOL>% (short_name, str(e), required))<EOL><DEDENT>elif '<STR_LIT>' in str(e):<EOL><INDENT>required = join_quoted(spec.args[<NUM_LIT:1>:-len(spec.defaults)])<EOL>optional = join_quoted(spec.args[-len(spec.defaults):])<EOL>raise RuntimeError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (<EOL>short_name, str(e), required, optional))<EOL><DEDENT>raise<EOL><DEDENT><DEDENT><DEDENT>chain = itertools.chain.from_iterable(<EOL>e.short_name if _is_collection(e.short_name) else [e.short_name]<EOL>for e in sc)<EOL>avail_names = '<STR_LIT:U+002CU+0020>'.join(str(n) for n in chain)<EOL>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' % (short_name, avail_names))<EOL>
Find the subclass, `kls` of baseclass with class attribute `short_name`
that matches the supplied `short_name`, and then instantiate and return
that class with:

    return kls(**params)

This function also tries its best to catch any possible TypeErrors due
to binding of the arguments, and rethrows them as nicely formatted
RuntimeErrors that are suitable for showing to users.