How to use the dataclasses.asdict 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 codeforpdx / recordexpungPDX / src / backend / expungeservice / record_editor.py View on Github external
def _update_or_delete_charge(charges, case_number, edit_action_ambiguous_charge_id, edit) -> OeciCharge:
        charge = next((charge for charge in charges if charge.ambiguous_charge_id == edit_action_ambiguous_charge_id))
        charge_dict = RecordEditor._parse_charge_edits(edit)
        charge_type_string = charge_dict.pop("charge_type", None)
        edited_oeci_charge = replace(charge, **charge_dict)
        if charge_type_string:
            charge_type_data = {
                "id": f"{charge.ambiguous_charge_id}-0",
                "case_number": case_number,
                "charge_type": RecordEditor._get_charge_type(charge_type_string),
                **asdict(edited_oeci_charge),
            }
            new_charge = from_dict(data_class=Charge, data=charge_type_data)
            return new_charge
        else:
            return edited_oeci_charge
github Enforcer / clean-architecture / auctioning_platform / web_app / web_app / blueprints / shipping.py View on Github external
def get_next_package(query: GetNextPackage) -> Response:
    result = query.query()
    if not result:
        abort(404)
    return make_response(jsonify(dataclasses.asdict(result)))  # type: ignore
github binderclip / code-snippets-python / packages / dataclasses_sp / hello_dataclasses.py View on Github external
def main():
    obj = SimpleDataObject(1, 'aaa')
    print(obj)
    print(asdict(obj))

    obj2 = SimpleDataObject(100, obj)
    print(obj2)
    print(asdict(obj2))

    d = {'field_a': 1, 'field_b': 'aaa'}
    obj = SimpleDataObject(field_a=1, field_b='aaa')
    print(obj)
    obj = SimpleDataObject(**d)
    print(obj)
    print(type(obj))
github synesthesiam / voice2json / voice2json / record.py View on Github external
def generate_intent() -> typing.Dict[str, typing.Any]:
        # Generate sample intent
        path = next(random_paths)
        _, recognition = rhasspynlu.fsticuffs.path_to_recognition(path, intent_graph)
        assert recognition, "Path to recognition failed"
        return dataclasses.asdict(recognition)
github pioneers / PieCentral / runtime / runtime / util / __init__.py View on Github external
def as_dict(self) -> dict:
        stats = dataclasses.asdict(self)
        if self.packets_recv:
            stats['mean_bytes_recv'] = round(self.bytes_recv/self.packets_recv, self.rounding)
        if self.packets_sent:
            stats['mean_bytes_sent'] = round(self.bytes_sent/self.packets_sent, self.rounding)
        return stats
github binderclip / code-snippets-python / packages / dataclasses_sp / hello_dataclasses.py View on Github external
def main():
    obj = SimpleDataObject(1, 'aaa')
    print(obj)
    print(asdict(obj))

    obj2 = SimpleDataObject(100, obj)
    print(obj2)
    print(asdict(obj2))

    d = {'field_a': 1, 'field_b': 'aaa'}
    obj = SimpleDataObject(field_a=1, field_b='aaa')
    print(obj)
    obj = SimpleDataObject(**d)
    print(obj)
    print(type(obj))
github thg-consulting / inspectortiger / inspectortiger / session.py View on Github external
def group_by(self, inspection, group):
        for plugin, reports in inspection.items():
            for report in reports:
                if report.code not in self.config.blacklist.codes:
                    if group is Group.PLUGIN:
                        yield plugin, asdict(report)
                    elif isinstance(group, Group):
                        yield getattr(report, group.name.lower()), {
                            "plugin": plugin,
                            **asdict(report),
                        }
                    else:
                        raise ValueError(f"Unsupported grouping, {group}.")
github osrsbox / osrsbox-db / osrsbox / monsters_api / monster_properties.py View on Github external
def construct_json(self) -> Dict:
        """Construct dictionary/JSON for exporting or printing.

        :return json_out: All class attributes stored in a dictionary.
        """
        return asdict(self)