Romain Vincent :
I've read some parts of the Pydantic library and done some tests but I can't figure out what is the added benefit of using Field(...)
(with no extra options) in a schema definition instead of simply not adding a default value.
So what is added here:
from pydantic import BaseModel, Field
class Model(BaseModel):
a: int = Field(...)
that is not here:
from pydantic import BaseModel
class Model(BaseModel):
a: int
Is there any special behaviour that I'm missing?
SColvin :
These are basically the same, the reason you might want to do this is so you can supply other settings to the field via kwargs to Field()
.
If you have no other settings for the field, using Field()
is unnecessary.
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=279359&siteId=1