You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromtypingimportGenericfromtypingimportTypeVarfromtypingimportListfrompydantic.genericsimportGenericModelfrompydanticimportBaseModelT=TypeVar("T")
classBaseList(GenericModel, Generic[T]):
__root__: List[T]
classTest(BaseModel):
mylist: BaseList[int]
Test(mylist=[1,2,3,4])
# Test(mylist=BaseList[int](__root__=[1, 2, 3, 4]))Test(mylist=BaseList[int](__root__=[1,2,3,4]))
# ---------------------------------------------------------------------------# ValidationError Traceback (most recent call last)# <ipython-input-10-c373af038c5b> in <module># ----> 1 Test(mylist=BaseList[int](__root__=[1,2,3,4]))# # /usr/local/lib/python3.8/dist-packages/pydantic/main.cpython-38-x86_64-linux-gnu.so in pydantic.main.BaseModel.__init__()# # ValidationError: 1 validation error for Test# mylist -> __root__# value is not a valid list (type=type_error.list)
Certainly no error with pydantic 1.6.1 (I tested this locally).
Probably also no errors with versions <1.8 because we have automatic tests in place with the newest package versions and these tests only fired yesterday.
Certainly no error with pydantic 1.6.1 (I tested this locally).
Probably also no errors with versions <1.8 because we have automatic tests in place with the newest package versions and these tests only fired yesterday.
On a first glance the documentation does not seem to have changed - so I assume also the behaviour should not have changed with the 1.8 release. See https://pydantic-docs.helpmanual.io/usage/models/#generic-models and
https://pydantic-docs.helpmanual.io/usage/models/#custom-root-types
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:The text was updated successfully, but these errors were encountered: