未提供项目描述
项目描述
可扩展Pydantic
此插件提供了一个新的类型,用于将Pydantic模型声明为可扩展类。
从版本1.0.0开始,它只支持Pydantic >= 2.0.0。
from pydantic import BaseModel
from extendable_pydantic import ExtendableModelMeta
from extendable import context, registry
class Location(BaseModel, metaclass=ExtendableModelMeta):
lat = 0.1
lng = 10.1
class ExtendedLocation(Location, extends=Location):
name: str
_registry = registry.ExtendableClassesRegistry()
context.extendable_registry.set(_registry)
_registry.init_registry()
loc = Location(**{"lat": 12.3, "lng": 13.2, "name": "My Loc"})
loc.model_dump() == {"lat": 12.3, "lng": 13.2, "name": "My Loc"}
#> True
loc.model_json_schema()
#> {'title': 'Location', 'type': 'object', 'properties': {'lat': {'title': 'Lat', 'default': 0.1, 'type': 'number'}, 'lng': {'title': 'Lng', 'default': 10.1, 'type': 'number'}, 'name': {'title': 'Name', 'type': 'string'}}, 'required': ['name']}
开发
pip install -e .
然后,将extendable_pydantic_patcher.pth
复制到$VIRTUAL_ENV/lib/python3.10/site-packages
。
发布
- 运行 ``bumpversion patch|minor|major --list
- 检查上一个命令返回的new_version值
- 运行 towncrier build。
- 检查并提交更新的HISTORY.rst。
- git tag {new_version} ; git push --tags。