Skip to content

An Optional type expects 1 subtype #122

@ruaridhw

Description

@ruaridhw

desert throws an error when a dataclass has more than one subtype other than None

import desert
from dataclasses import dataclass
from typing import Union

from marshmallow import Schema

@dataclass
class MyOptionalKlass:
    a: Union[float, str, None] = 3

schema = desert.schema(MyOptionalKlass)
#> ValueError: too many values to unpack (expected 1)

I think this is to do with the check of is_optional_type() before is_union_type(). I think within the is_optional_type() branch we should create subfields for all remaining subtypes other than NoneType.

Even without the None in the type, the default value of the field is still <marshmallow.missing> rather than 3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions