Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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})"
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})"
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