Closed scnerd closed 1 year ago
I get some odd results when using an Optional[Union[...]] type when a regular Union[...] works great.
Optional[Union[...]]
Union[...]
from dataclasses import dataclass from typing import Optional, Union, List import dacite @dataclass class A: x: str @dataclass class B: y: Optional[Union[List[A], A]] dacite.from_dict(B, {'y': 'lol'}, config=dacite.Config(cast=[A])) # B(y=A(x='lol')) <-- correct dacite.from_dict(B, {'y': ['lol']}, config=dacite.Config(cast=[A])) # B(y=[A(x=A(x='lol'))]) <-- incorrect
This bug doesn't arise if Optional is omitted:
Optional
@dataclass class B: y: Union[List[A], A] dacite.from_dict(B, {'y': 'lol'}, config=dacite.Config(cast=[A])) # B(y=A(x='lol')) dacite.from_dict(B, {'y': ['lol']}, config=dacite.Config(cast=[A])) # B(y=[A(x='lol')])
Versions:
dacite
Same problem as #163 ?
@scnerd should be fixed now (https://github.com/konradhalas/dacite/pull/164)
I get some odd results when using an
Optional[Union[...]]
type when a regularUnion[...]
works great.This bug doesn't arise if
Optional
is omitted:Versions:
dacite
: 1.6.0