Created
May 19, 2022 13:44
-
-
Save chrisvdg/46bf214a13780123a427bc39186ef532 to your computer and use it in GitHub Desktop.
Test script that shows default empty list of Pydantic does a deep copy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import field | |
from typing import List | |
from pydantic import BaseModel, Field | |
class ClassWithList(BaseModel): | |
list: List = Field([], description="A list field") | |
a = ClassWithList() | |
b = ClassWithList() | |
b.list = ["a", "b"] | |
print(f"List {a=}") | |
print(f"List {b=}") | |
# Prints: | |
# List a=ClassWithList(list=[]) | |
# List b=ClassWithList(list=['a', 'b']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment