konradhalas / dacite

Simple creation of data classes from dictionaries.
MIT License
1.72k stars 107 forks source link

Feature proposal: as_dict method which uses dacite's Config #95

Closed mprzewie closed 4 years ago

mprzewie commented 4 years ago

I know the standard dataclasses lib provides asdict by default, but it would be nice to be able to boost it with many of the awesome functionalities Dacite provides, such as type hooks.

My use case is serialization/deserialization of objects such as pathlib Paths or numpy arrays. I'd be happy to help with it if you are considering this a viable direction for dacite.

Thanks for an awesome project! It's really useful :)

konradhalas commented 4 years ago

Hi @mprzewie - thank you for using dacite, I'm glad that it's useful in your projects :)

This idea pop up in my head a few times but TBH I was always against it. I thought that it's out of scope of this project - I always want to focus on this single missing function which is transformation from raw dict to data class.

But on the other hand it sounds like a perfect addition which will add some sort of symmetry to the project.

Do you see any other pros to have own implementation of asdict? E.g. I see in dataclass.asdict implementation that it supports only list, tuple and dict, so it will not transform your inner dataclasses if you put them into set.

konradhalas commented 4 years ago

@mprzewie I'm closing this issue now, but please reopen if will have some ideas/PRs/etc.