我正在尝试按如下方式使用 Pydantic:
from pydantic import BaseModel
class A(BaseModel):
prop1: str
prop2: str
class B(BaseModel):
a: A
data = {
'prop1': 'some value',
'prop2': 'some other value'
}
b = B(**data)
这给了我以下错误:
Traceback (most recent call last):
File "main.py", line 18, in <module>
b = B(**data)
File "pydantic/main.py", line 283, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for B
a
field required (type=value_error.missing)
pydantic 是否可以创建所需的A
实例B
?