-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Description
Bug
Please complete:
- OS: 19.10
- Python version
import sys; print(sys.version): 3.6.8 [GCC 9.2.1 20191008] - Pydantic version
import pydantic; print(pydantic.VERSION): 1.2
I want to create model Foo, that contains collection of Bars:
from typing import Set, Tuple, List
from pydantic import BaseModel
class Bar(BaseModel):
bar: str = 'bar_value'
def __hash__(self):
return self.bar.__hash__()
class FooTuple(BaseModel):
bars: Tuple[Bar]
class FooSet(BaseModel):
bars: Set[Bar]
class FooList(BaseModel):
bars: List[Bar]
if __name__ == '__main__':
FooList(bars=[Bar()]).dict()
FooTuple(bars=(Bar(),)).dict()
FooSet(bars={Bar()}).dict()
...Dict method recursively converts models to dictionaries and tries to put them in the same containers they were in. It falls down for Set because of dict type is unhashable.
hxmn, DBCerigo, thomasleveil, jduchateau, yalaudah and 1 more