CoolFace
Apppublic

mosi77/zan

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
utils.py38 linesDownload Raw Back to diffq
1# Copyright (c) Facebook, Inc. and its affiliates.2# All rights reserved.3#4# This source code is licensed under the license found in the5# LICENSE file in the root directory of this source tree.6 7import inspect8from typing import Optional, List9 10 11def simple_repr(obj, attrs: Optional[List[str]] = None, overrides={}):12    """13    Return a simple representation string for `obj`.14    If `attrs` is not None, it should be a list of attributes to include.15    """16    params = inspect.signature(obj.__class__).parameters17    attrs_repr = []18    if attrs is None:19        attrs = params.keys()20    for attr in attrs:21        display = False22        if attr in overrides:23            value = overrides[attr]24        elif hasattr(obj, attr):25            value = getattr(obj, attr)26        else:27            continue28        if attr in params:29            param = params[attr]30            if param.default is inspect._empty or value != param.default:31                display = True32        else:33            display = True34 35        if display:36            attrs_repr.append(f"{attr}={value}")37    return f"{obj.__class__.__name__}({','.join(attrs_repr)})"38