Created
June 29, 2017 00:09
-
-
Save xmonader/d583994826e72f554150f611d17899ff to your computer and use it in GitHub Desktop.
This file contains 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 typchk import * | |
def validateargs(**kwargs): | |
c = Checker(kwargs) | |
def decorator(f): | |
def wrapper(*args, **funkwargs): | |
try: | |
if funkwargs: | |
res = c.check(funkwargs) | |
else: | |
if args: | |
res = c.check(dict(zip(f.__code__.co_varnames, args))) | |
except: | |
raise | |
else: | |
return f(*args, **funkwargs) | |
return wrapper | |
return decorator | |
@validateargs(a=int, b=int, c=Option) | |
def add2(a, b, c=None): | |
return a+b | |
print(add2(3, 4)) | |
print(add2("ahmed", 3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment