Skip to content

Instantly share code, notes, and snippets.

@chrisvdg
Created May 19, 2022 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisvdg/46bf214a13780123a427bc39186ef532 to your computer and use it in GitHub Desktop.
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
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