Code Duplication    Length = 15-15 lines in 2 locations

openscap_report/dataclasses/dataclasses.py 2 locations

@@ 1146-1160 (lines=15) @@
1143
    return _astuple_inner(obj, tuple_factory)
1144
1145
1146
def _astuple_inner(obj, tuple_factory):
1147
    if _is_dataclass_instance(obj):
1148
        result = []
1149
        for f in fields(obj):
1150
            value = _astuple_inner(getattr(obj, f.name), tuple_factory)
1151
            result.append(value)
1152
        return tuple_factory(result)
1153
    if isinstance(obj, (list, tuple)):
1154
        return type(obj)(_astuple_inner(v, tuple_factory) for v in obj)
1155
    if isinstance(obj, dict):
1156
        return type(obj)(
1157
            (_astuple_inner(k, tuple_factory), _astuple_inner(v, tuple_factory))
1158
            for k, v in obj.items()
1159
        )
1160
    return copy.deepcopy(obj)
1161
1162
1163
def make_dataclass(
@@ 1105-1119 (lines=15) @@
1102
    return _asdict_inner(obj, dict_factory)
1103
1104
1105
def _asdict_inner(obj, dict_factory):
1106
    if _is_dataclass_instance(obj):
1107
        result = []
1108
        for f in fields(obj):
1109
            value = _asdict_inner(getattr(obj, f.name), dict_factory)
1110
            result.append((f.name, value))
1111
        return dict_factory(result)
1112
    if isinstance(obj, (list, tuple)):
1113
        return type(obj)(_asdict_inner(v, dict_factory) for v in obj)
1114
    if isinstance(obj, dict):
1115
        return type(obj)(
1116
            (_asdict_inner(k, dict_factory), _asdict_inner(v, dict_factory))
1117
            for k, v in obj.items()
1118
        )
1119
    return copy.deepcopy(obj)
1120
1121
1122
def astuple(obj, *, tuple_factory=tuple):