-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to customize from_dict per data class #122
base: master
Are you sure you want to change the base?
Conversation
would be nice indeed! |
t: str | ||
|
||
def from_dict(data_class, data, config): | ||
data["t"] = "prefix {}".format(data["t"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This prefix can be done with the builtin __post_init__
too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but this is just an example. The main goal is to have a place to reshape the dictionary before we create a data class from it.
Is there any plan to land these changes? I would very much like this feature to be landed. Or is there a good workaround to achieve the same behavior? |
@mwerlberger you can use my fork for now https://pypi.org/project/tonalite/ |
@konradhalas I've updated the MR as I can see some life in this repository again. |
In some cases when loading a nested structure of data classes you might need to do a customization for some of them. This change allows customizing a
from_dict
method for each data class.Code sample from the test