How to use the dataclasses._FIELDS function in dataclasses

To help you get started, we’ve selected a few dataclasses examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github icon-project / loopchain / loopchain / blockchain / transactions / transaction.py View on Github external
def __str__(self):
        fields = getattr(self, _FIELDS, None)
        if fields is None:
            return ""

        fields = [f for f in fields.values() if f._field_type is _FIELD]
        fields_str = ', '.join(f"{f.name}={getattr(self, f.name)}" for f in fields)
        return f"{self.__class__.__qualname__}({fields_str})"
github icon-project / loopchain / loopchain / blockchain / blocks / block.py View on Github external
def _dataclass__str__(self):
    fields = getattr(self, _FIELDS, None)
    if fields is None:
        return ""

    fields = [f for f in fields.values() if f._field_type is _FIELD]
    fields_str = ', '.join(f"{f.name}={getattr(self, f.name)}" for f in fields)
    return f"{self.__class__.__qualname__}({fields_str})"
github Fatal1ty / mashumaro / mashumaro / serializer / base / metaprogramming.py View on Github external
def defaults(self):
        d = {}
        for ancestor in self.cls.__mro__[-1:0:-1]:
            if is_dataclass(ancestor):
                for field in getattr(ancestor, _FIELDS).values():
                    d[field.name] = field.default
        for name in self.__get_fields(recursive=False):
            d[name] = self.namespace.get(name, MISSING)
        return d