f | from functools import wraps | f | from functools import wraps |
| | | |
| | | |
n | def cast(tyte): | n | def cast(t): |
| def _repeat(f): | | def decorator(f): |
| @wraps(f) | | @wraps(f) |
n | def inner(*args, **kwargs): | n | def new_f(*args): |
| try: | | try: |
n | return tyte(f(*args)) | n | return t(f(*args)) |
| except BaseException: | | except BaseException: |
| return f(*args) | | return f(*args) |
n | return inner | n | return new_f |
| return _repeat | | return decorator |
| | | |
t | # @cast(int) | t | |
| # 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) | | |
| | | |