konradhalas / dacite

Simple creation of data classes from dictionaries.
MIT License
1.76k stars 106 forks source link

add option to catch ambiguous union resolution #88

Closed sinback closed 4 years ago

sinback commented 4 years ago

Hi. I'm not sure if this feature is desired in dacite, but we patched our own fork of dacite to have it since it helps our team feel a little saner when resolving polymorphic union types. Let me know if you have comments or requests.

Add a config flag, no_ambiguous_resolution, to raise an error if a dacite dataclass construction is being performed on a datatype which can be resolved multiple ways.

I added a test also which demonstrates the situation that this flag can help catch.

konradhalas commented 4 years ago

Hi @sinback - thank you for PR :)

I like it, It makes sense, but let me think about it for a while. Union is a tricky type. TBH it should be banned ;)

konradhalas commented 4 years ago

I had to make a few minor amendments, but it's now in master branch 🎉 Check ff3f5fc2b5c0065cafeaf3c6be8b453b70a05086. Thank you for your contribution!