Code Duplication    Length = 14-14 lines in 2 locations

openscap_report/dataclasses.py 2 locations

@@ 1054-1067 (lines=14) @@
1051
    return _astuple_inner(obj, tuple_factory)
1052
1053
1054
def _astuple_inner(obj, tuple_factory):
1055
    if _is_dataclass_instance(obj):
1056
        result = []
1057
        for f in fields(obj):
1058
            value = _astuple_inner(getattr(obj, f.name), tuple_factory)
1059
            result.append(value)
1060
        return tuple_factory(result)
1061
    elif isinstance(obj, (list, tuple)):
1062
        return type(obj)(_astuple_inner(v, tuple_factory) for v in obj)
1063
    elif isinstance(obj, dict):
1064
        return type(obj)((_astuple_inner(k, tuple_factory), _astuple_inner(v, tuple_factory))
1065
                          for k, v in obj.items())
1066
    else:
1067
        return copy.deepcopy(obj)
1068
1069
1070
def make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True,
@@ 1014-1027 (lines=14) @@
1011
    return _asdict_inner(obj, dict_factory)
1012
1013
1014
def _asdict_inner(obj, dict_factory):
1015
    if _is_dataclass_instance(obj):
1016
        result = []
1017
        for f in fields(obj):
1018
            value = _asdict_inner(getattr(obj, f.name), dict_factory)
1019
            result.append((f.name, value))
1020
        return dict_factory(result)
1021
    elif isinstance(obj, (list, tuple)):
1022
        return type(obj)(_asdict_inner(v, dict_factory) for v in obj)
1023
    elif isinstance(obj, dict):
1024
        return type(obj)((_asdict_inner(k, dict_factory), _asdict_inner(v, dict_factory))
1025
                          for k, v in obj.items())
1026
    else:
1027
        return copy.deepcopy(obj)
1028
1029
1030
def astuple(obj, *, tuple_factory=tuple):