f | from functools import wraps | f | from functools import wraps |
| | | |
| | | |
n | def cast(t): | n | def cast(tyte): |
| def decorator(f): | | def _repeat(f): |
| @wraps(f) | | @wraps(f) |
n | def new_f(*args): | n | def inner(*args, **kwargs): |
| try: | | try: |
n | return t(f(*args)) | n | return tyte(f(*args)) |
| except BaseException: | | except BaseException: |
| return f(*args) | | return f(*args) |
n | return new_f | n | return inner |
| return decorator | | return _repeat |
| | | |
t | | t | # @cast(int) |
| | | # def fun(a, b): |
| | | # return a * 2 + b |
| | | # print(fun(12, 34) * 2) |
| | | # print(fun("12", "34") * 2) |
| | | # print(fun(12.765, 34.654) * 2) |
| | | |