How to keep the attributes strictly to the properties of a pydantic class

Viewed 149

For example, this is my class:

from pydantic import BaseModel

class Config(BaseModel):
    name: str
    age: int

And here's a dictionary:

data = {"name": "XYZ", "age": 18, "height": "180cm"}

Now because height is not a property of the Config class, doing

d = Config(**data)

should throw an error but it doesn't. How can I make it throw an error if the dictionary isn't exactly what the class wants?

1 Answers
Related