有可能创建一个pydantic模型的weakref吗
from pydantic import BaseModel
from uuid import UUID
class JEdgeModel(BaseModel):
uid: UUID
startSocket: UUID
destnSocket: UUID
a = JEdgeModel(uid='abd6fc3f882544f5b75661c92fccbd0d', startSocket='abd6fc3f882544f5b75661c92fccbd0d', destnSocket='abd6fc3f882544f5b75661c92fccbd0d')
wk = weakref.ref(a)
我得到以下错误:
cannot create weak reference to 'JEdgeModel' object
有没有办法达到同样的效果
从documentation
因此,只需将
__weakref__
添加到模型中的__slot__
相关问题 更多 >
编程相关推荐