s-knibbs / dataclasses-jsonschema

JSON schema generation from dataclasses
MIT License
166 stars 38 forks source link

List of Nullable values are not converted to None in the to_dict function #136

Open Golyo88 opened 3 years ago

Golyo88 commented 3 years ago

to_dict not handled correctly where the field is a List with Nullable values

@dataclass(frozen=True)
class Range(JsonSchemaMixin):
    range: List[Nullable[float]]
    not_range: Nullable[float]

r = Range.from_dict({'range': [1.0, 2.0, None, 3.0], 'not_range': None})
r.to_dict()
{'range': [1.0, 2.0, <dataclasses_jsonschema.type_defs._NULL_TYPE object at 0x10c002e50>, 3.0], 'not_range': None}

As you can see Nullable field's value will convert to None in the to_dict() function, but the Nullable items of a List is not