Created
June 24, 2017 01:23
-
-
Save namoshizun/f021847df928420125c82aa42a2b1da0 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
def checktype(*types): | |
def typerror(expect, got): | |
raise TypeError('expecting {}, got{}'.format(expect, type(got))) | |
def checker(fn): | |
def receiver(*args, **kwargs): | |
for _type, arg in zip(types, args): | |
type(arg) is _type or typerror(_type, arg) | |
return fn(*args, **kwargs) | |
return receiver | |
return checker | |
@checktype(int, str) | |
def foo(num, word): | |
print(num ,word) | |
foo(1, '2') | |
# foo(1, 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment