def generic_repr(obj, additional_kw=(), to_inspect=None):
    """Produce a __repr__() based on direct association of the __init__()
    specification vs. same-named attributes present.

    """
    if to_inspect is None:
        to_inspect = [obj]
    else:
        to_inspect = _collections.to_list(to_inspect)

    missing = object()

    pos_args = []
    kw_args = _collections.OrderedDict()
    vargs = None
    for i, insp in enumerate(to_inspect):
        try:
            (_args, _vargs, vkw, defaults) = \
                inspect.getargspec(insp.__init__)
        except __HOLE__:
            continue
        else:
            default_len = defaults and len(defaults) or 0
            if i == 0:
                if _vargs:
                    vargs = _vargs
                if default_len:
                    pos_args.extend(_args[1:-default_len])
                else:
                    pos_args.extend(_args[1:])
            else:
                kw_args.update([
                    (arg, missing) for arg in _args[1:-default_len]
                ])

            if default_len:
                kw_args.update([
                    (arg, default)
                    for arg, default
                    in zip(_args[-default_len:], defaults)
                ])
    output = []

    output.extend(repr(getattr(obj, arg, None)) for arg in pos_args)

    if vargs is not None and hasattr(obj, vargs):
        output.extend([repr(val) for val in getattr(obj, vargs)])

    for arg, defval in kw_args.items():
        try:
            val = getattr(obj, arg, missing)
            if val is not missing and val != defval:
                output.append('%s=%r' % (arg, val))
        except:
            pass

    if additional_kw:
        for arg, defval in additional_kw:
            try:
                val = getattr(obj, arg, missing)
                if val is not missing and val != defval:
                    output.append('%s=%r' % (arg, val))
            except:
                pass

    return "%s(%s)" % (obj.__class__.__name__, ", ".join(output))
dataset/ETHPy150Open goFrendiAsgard/kokoropy/kokoropy/packages/sqlalchemy/util/langhelpers.py/generic_repr