Created
March 22, 2012 10:46
-
-
Save AeroNotix/2157646 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def arg_types(*types): | |
| def wrapper(function): | |
| def inner_wrap(*wrapped_args): | |
| if len(types) != len(wrapped_args): | |
| raise Exception(''.join( | |
| [ | |
| 'Incorrect argument amount, this ', | |
| 'argument requires {} argument and ', | |
| 'you provided {} to the decorator.'] | |
| ).format(len(wrapped_args), len(types))) | |
| for pair in zip(types, wrapped_args): | |
| if type(pair[1]) != pair[0]: | |
| raise TypeError | |
| return function(*wrapped_args) | |
| return inner_wrap | |
| return wrapper | |
| @arg_types(int) | |
| def type_hinted_function(x, y): | |
| return x, y | |
| print type_hinted_function(1, 10) | |
| type_hinted_function('1', 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment