Closed AlwxSin closed 5 years ago
I think this error may be fixed by adding addition check for new type:
types = tuple(t.__supertype__ if is_new_type(t) else t for t in types)
after this line: https://github.com/konradhalas/dacite/blob/ece070cc3c25e86634086db8ee4f2e45bdfe6fe5/dacite/types.py#L53 @AlwxSin Can you check this? If everything is good, I will add tests and open a PR.
@GreyZmeem sorry, but for several days I'll have only smartphone. I think using my example in issue description should be enough for testing.
@AlwxSin thank you for reporting this issue! It's definitely a bug. I've fixed it in the latest commit - 574015d
@GreyZmeem thank you for your suggestion - this was a problematic function.
@konradhalas I did not open a PR, because the fix I proposed only works in simple situations when underlying type is a generic type. But will fail if you have nested complex types like:
MyType = NewType("MyType", str)
MyType2 = NewType("MyType2", MyType)
MyType3 = NewType("MyType3", Optional[MyType])
...
It seems a recursive is_instance
call needed for all NewTypes, if its __supertype__
is not a generic type.
@GreyZmeem hmm, interesting, I will check.
Example
Output
This is happens only if I use
Optional[NewType]
. WithoutOptional
dacite works like charm.