from_dict ignores extraneous data
See original GitHub issueProbably related to type validation, but I noticed that dacite ignores extraneous data passed to from_dict
.
I expected the last example to also raise an exception.
> @dataclass
> class A:
> x: str
> A(x="hello")
A(x='hello')
> A(x="hello", y="world")
TypeError: __init__() got an unexpected keyword argument 'y'
> dacite.from_dict(data_class=A, data={"x":"hello", "y": "world"})
A(x='hello')
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Add dictionary to pandas data frame and ignore extra values
I want the columns I defined in the data frame only to add to data frame. As of now I'm adding all the...
Read more >lidatong/dataclasses-json: Easily serialize Data ... - GitHub
Easily serialize Data Classes to and from JSON. ... (the from_dict method ignores them, when loading using schema() a ValidationError is raised.) ...
Read more >Dataclass Wizard — Dataclass Wizard 0.22.2 documentation
The default behavior is to ignore any unknown or extraneous JSON keys that are encountered when from_dict or from_json is called, and emit...
Read more >pandas.DataFrame.from_dict — pandas 1.5.2 documentation
Construct DataFrame from dict of array-like or dicts. Creates DataFrame object from dictionary by columns or by index allowing dtype specification. Parameters.
Read more >Does anyone know why my use of URLSession doesn't return ...
I'm trying to learn how to fetch data from a JSON file hosted on 511.org into a SwiftUI project. More specifically, I am...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Let’s choose this option:
I will try to implement it in upcoming week.
I am not sure if this should be a default behaviour though. Such a
strict mode
IMHO should be enabled by setting it indacite.Config
and with ability to specify where should it be strict.By “where” I mean the scenario like: