| TypeCast/karry99 | TypeCast/Aleksyav | ||||
|---|---|---|---|---|---|
| n | 1 | #!/usr/bin/env python | n | ||
| 2 | # coding: utf-8 | ||||
| 3 | |||||
| 4 | # In[9]: | ||||
| 5 | |||||
| 6 | |||||
| 7 | from functools import wraps | 1 | from functools import wraps | ||
| 8 | 2 | ||||
| 9 | 3 | ||||
| t | 10 | # In[11]: | t | ||
| 11 | |||||
| 12 | |||||
| 13 | def cast(to_type): | 4 | def cast(t): | ||
| 14 | def decorator(function_to_decorate): | 5 | def decorator(f): | ||
| 15 | @wraps(function_to_decorate) | 6 | @wraps(f) | ||
| 16 | def wrapper(*args, **kwargs): | 7 | def newfun(*args, **kwargs): | ||
| 17 | return to_type(function_to_decorate(*args, **kwargs)) | 8 | return t(f(*args, **kwargs)) | ||
| 18 | return wrapper | 9 | return newfun | ||
| 19 | return decorator | 10 | return decorator | ||
| 20 | 11 | ||||
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||