Deal - DbC、检查Python 值、异常和副作用


文章目录


一、关于 Deal

Deal 是用于 design by contract (DbC) 和 检查值、异常和副作用的Python库。简而言之,交易使您能够编写bug的代码。

通过在代码中添加一些装饰器,您可以获得免费测试、静态分析、形式验证等等。阅读介绍开始。



特点


二、安装

shell 复制代码
python3 -m pip install --user 'deal[all]'

三、30秒内使用 Deal

python 复制代码
# the result is always non-negative
@deal.post(lambda result: result >= 0)
# the function has no side-effects
@deal.pure
def count(items: List[str], item: str) -> int:
    return items.count(item)

# generate test function
test_count = deal.cases(count)

现在我们可以:

  • 运行python3 -m deal lintflake8以静态检查错误。
  • 运行python3 -m deal testpytest生成并运行测试。
  • 只需在项目中使用该函数并在运行时检查错误。

阅读更多的文档


四、其它

贡献

欢迎投稿!您可以贡献的一些想法:

  • 为linter添加新的检查。
  • 改善文档。
  • 添加更多测试。
  • 提高性能。
  • 找到bug?修好它!
  • 写了一篇关于交易的文章?太好了。让我们把它添加到README.md中。
  • 没有时间编码?别担心!只需告诉您的朋友和订阅者该项目。更多用户->更多贡献者->更多酷功能。

要在本地运行测试,您只需要任务。运行task all来运行所有代码格式化程序、linter和测试。

谢谢你❤️


2025-03-19(三)

相关推荐
敏编程21 小时前
一天一个Python库:jsonschema - JSON 数据验证利器
python
前端付豪21 小时前
LangChain记忆:通过Memory记住上次的对话细节
人工智能·python·langchain
databook1 天前
ManimCE v0.20.1 发布:LaTeX 渲染修复与动画稳定性提升
python·动效
花酒锄作田1 天前
使用 pkgutil 实现动态插件系统
python
前端付豪2 天前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件
人工智能·python·langchain
曲幽2 天前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
老赵全栈实战2 天前
Pydantic配置管理最佳实践(一)
python
阿尔的代码屋2 天前
[大模型实战 07] 基于 LlamaIndex ReAct 框架手搓全自动博客监控 Agent
人工智能·python
AI探索者3 天前
LangGraph StateGraph 实战:状态机聊天机器人构建指南
python
AI探索者3 天前
LangGraph 入门:构建带记忆功能的天气查询 Agent
python