Skip to main content

@accepts 装饰器检查参数类型

项目描述

安装

$ [sudo] pip install accepts

特征

  • 支持多种类型参数
  • 支持参数
  • 人类可读的详细异常消息

例子

>>> from accepts import accepts
>>> @accepts(int)
def inc(value):
	return value+1

>>> inc(1) # ok

# multiple types
>>> @accepts((int,float))
>>> inc(1.5) # ok
>>> inc("string")
TypeError: inc() argument #0 is not instance of (<class 'int'>, <class 'float'>)

# None
>>> @accepts((int,float,type(None)))

readme42.com

项目详情


发布历史 发布通知| RSS订阅