【发布时间】:2017-07-17 12:21:39
【问题描述】:
from inspect import signature
from typing import get_type_hints
def check_range(f):
def decorated(*args, **kwargs): #something should be modified here
counter=0
# use get_type_hints instead of __annotations__
annotations = get_type_hints(f)
# bind signature to arguments and get an
# ordered dictionary of the arguments
b = signature(f).bind(*args, **kwargs).arguments
for name, value in b.items():
if not isinstance(value, annotations[name]):
msg = 'Not the valid type'
raise ValueError(msg)
counter+=1
return f(*args, **kwargs) #something should be modified here
return decorated
@check_range
def foo(a: int, b: list, c: str):
print(a,b,c)
前段时间我又问了一个问题,得到了很好的回答。但是弹出了另一个不同的问题......我如何让它不在交互式空闲中显示:
但是要显示这个:
【问题讨论】:
标签: python python-3.x python-decorators