How to give a Pydantic list field a default value?
For pydantic you can use mutable default value, like: class Foo(BaseModel): defaulted_list_field: List[str] = [] f1, f2 = Foo(), Foo() f1.defaulted_list_field.append(“hey!”) print(f1) # defaulted_list_field=[‘hey!’] print(f2) # defaulted_list_field=[] It will be handled correctly (deep copy) and each model instance will have its own empty list. Pydantic also has default_factory parameter. In the case of an empty … Read more