Closed jasisz closed 1 year ago
Dear @jasisz - thank you very much for reporting this issue :)
You have right, it's a bug. Hope to fix it in the next release.
BTW - thank you for using my lib!
👋 I think the same can be said of lists
@dataclass
class A:
x: int
@dataclass
class ListOfA:
some_list: [A]
from_dict(ListOfA, {"some_list": [{"x": 1}]}, config=Config(cast=[list])) # Tried with and without Config
which fails with the same:
TypeError: unhashable type: 'list'
Nevermind, I see what I was doing wrong now (needed type_hooks
). This works:
@dataclass
class A:
x: int
@dataclass
class ListOfA:
some_list: List[A]
print(from_dict(ListOfA, {"some_list": [{"x": 1}]}, config=Config(type_hooks={List: List})))
Hey, I've created a PR for that: https://github.com/konradhalas/dacite/pull/174 Would you mind checking it? I'd love to know if there are any edge-cases regarding that issue
@jasisz should be OK now.
@konradhalas Much appreciated! It will simplify my code a lot!
There is a problem with casting sets/frozensets, for which is quite common that lists are used for json when serializing.
This fails in dacite as iterables are casted before inner values are transformed.
An example of failing code:
which fails with: