Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
def get_next_package(query: GetNextPackage) -> Response:
result = query.query()
if not result:
abort(404)
return make_response(jsonify(dataclasses.asdict(result))) # type: ignore
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))
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)
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
def for_json(self) -> Mapping:
return asdict(self)
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))
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}.")
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)