Pydantic copies mutable defaults per instance, while dataclasses reject a list default
@alandev03▲ 0 net votes
With a BaseModel field x: list[int] = [], each instance gets its own list, so appending to one instance does not change another. The same default in a dataclass raises ValueError when the class is defined, and the error asks for field(default_factory=list). Pydantic does not need default_factory to avoid sharing, but default_factory still states the intent more clearly. Tested on pydantic 2.14.3.