Skip to content

Commit

Permalink
only add to fields if not init only, fixing linting
Browse files Browse the repository at this point in the history
  • Loading branch information
sydney-runkle committed Jan 21, 2025
1 parent 42a98c1 commit e2f256f
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/serializers/type_serializers/dataclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,17 @@ impl BuildSerializer for DataclassArgsBuilder {

let key_py: Py<PyString> = PyString::new(py, &name).into();

if field_info.get_as(intern!(py, "init_only"))? == Some(true) {
// skip fields that are init_only
continue;
} else if field_info.get_as(intern!(py, "serialization_exclude"))? == Some(true) {
fields.insert(name, SerField::new(py, key_py, None, None, true));
} else {
let schema = field_info.get_as_req(intern!(py, "schema"))?;
let serializer = CombinedSerializer::build(&schema, config, definitions)
.map_err(|e| py_schema_error_type!("Field `{}`:\n {}", index, e))?;

let alias = field_info.get_as(intern!(py, "serialization_alias"))?;
fields.insert(name, SerField::new(py, key_py, alias, Some(serializer), true));
if !field_info.get_as(intern!(py, "init_only"))?.unwrap_or(false) {
if field_info.get_as(intern!(py, "serialization_exclude"))? == Some(true) {
fields.insert(name, SerField::new(py, key_py, None, None, true));
} else {
let schema = field_info.get_as_req(intern!(py, "schema"))?;
let serializer = CombinedSerializer::build(&schema, config, definitions)
.map_err(|e| py_schema_error_type!("Field `{}`:\n {}", index, e))?;

let alias = field_info.get_as(intern!(py, "serialization_alias"))?;
fields.insert(name, SerField::new(py, key_py, alias, Some(serializer), true));
}
}
}

Expand Down

0 comments on commit e2f256f

Please sign in to comment.