Created
November 8, 2021 15:59
-
-
Save scidam/290d877d9c940fe5f933b104bcfde143 to your computer and use it in GitHub Desktop.
My solution (as is) to arg_checker challenge
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
| from functools import wraps | |
| def arg_checker(*arg_types): | |
| '''An argument checker decorator that checks both: | |
| - The number of variables that you use for a function | |
| - The type of each variable. | |
| Raises a TypeError if either of these fail''' | |
| def wrapper(func): | |
| @wraps(func) | |
| def wrapped(*args): | |
| if any(not isinstance(a, at) for a, at in zip(args, at))\ | |
| or len(arg_types) != len(args): | |
| raise TypeError("Hello, there is a type error with arguments") | |
| return func(*args) | |
| return wrapped | |
| return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment