Closed chebureki closed 1 year ago
I have a similar case where the key in the dictionary is a python reserved keyword "from"
@dataclass
class Packet:
from_call: str
to_call: str
data_packet = {
"from": "my friend"
"to": "to me"
}
Is there a way to have the "from" key in the dict set in the class as the "from_call" var?
@chebureki thank you for reporting this issue but I don't think we should add such config to this library (TBH we had such feature long time ago but I removed it). You can always clean up your data on your own before you pass them to from_dict
function.
How would one create a data class from a dict, with indexes which can't be python identifiers? I'm not too familiar with python, but I didn't seem to find a way to escape an identifier. e.g.:
How about a identifier mapping? Kinda hacky, but should do the job. e.g.:
Or is it better to let the user rename the dict indexes himself?