(obj, additional_kw=(), to_inspect=None, omit_kwarg=())
return "%s(%s)" % (obj.__class__.__name__, ", ".join(output))
Produce a __repr__() based on direct association of the __init__()
    specification vs. same-named attributes present.
Produce a __repr__() based on direct association of the __init__()
    specification vs. same-named attributes present.
Produce a __repr__ () based on direct association of the __init__ () specification vs . same - named attributes present .
def generic_repr(obj, additional_kw=(), to_inspect=None, omit_kwarg=()):
    """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:
            spec = compat.inspect_getfullargspec(insp.__init__)
        except TypeError:
            continue
        else:
            default_len = spec.defaults and len(spec.defaults) or 0
            if i == 0:
                if spec.varargs:
                    vargs = spec.varargs
                if default_len:
                    pos_args.extend(spec.args[1:-default_len])
                else:
                    pos_args.extend(spec.args[1:])
            else:
                kw_args.update(
                    [(arg, missing) for arg in spec.args[1:-default_len]]
                )

            if default_len:
                kw_args.update(
                    [
                        (arg, default)
                        for arg, default in zip(
                            spec.args[-default_len:], spec.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():
        if arg in omit_kwarg:
            continue
        try:
            val = getattr(obj, arg, missing)
            if val is not missing and val != defval:
                output.append("%s=%r" % (arg, val))
        except Exception:
            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 Exception:
                pass

    return "%s(%s)" % (obj.__class__.__name__, ", ".join(output))
def generic_repr ( obj , additional_kw = ( ) , to_inspect = None , omit_kwarg = ( ) ) : 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 : spec = compat . inspect_getfullargspec ( insp . __init__ ) except TypeError : continue else : default_len = spec . defaults and len ( spec . defaults ) or 0 if i == 0 : if spec . varargs : vargs = spec . varargs if default_len : pos_args . extend ( spec . args [ 1 : - default_len ] ) else : pos_args . extend ( spec . args [ 1 : ] ) else : kw_args . update ( [ ( arg , missing ) for arg in spec . args [ 1 : - default_len ] ] ) if default_len : kw_args . update ( [ ( arg , default ) for arg , default in zip ( spec . args [ - default_len : ] , spec . 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 ( ) : if arg in omit_kwarg : continue try : val = getattr ( obj , arg , missing ) if val is not missing and val != defval : output . append ( "%s=%r" % ( arg , val ) ) except Exception : 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 Exception : pass return "%s(%s)" % ( obj . __class__ . __name__ , ", " . join ( output ) )