41 ms·
What do you mean pass a dict? As in kwargs? kwargs = {'arg1':'val1', 'arg2':'val2'} my_obj = MyDataclass(**kwargs) Works fine for a dataclass with arg
by x187463 1y ago
What do you mean pass a dict? As in kwargs?
kwargs = {'arg1':'val1', 'arg2':'val2'}
my_obj = MyDataclass(**kwargs)
Works fine for a dataclass with arg1 and arg2 attributes.
- never_inline 1y agoDoesnt work recursively?
- maleldil 1y agoAt that point, you probably want proper validation with something like Pydantic, where you can use MyType.model_validate(dict).
- est 1y agoi mean if `arg2` wasn't defined in MyDataclass, there would an error. You have to exclude fields first.