Created
May 8, 2016 14:47
-
-
Save minus7/01b8a84984d1b99241b80d3ff36a3e2c to your computer and use it in GitHub Desktop.
Revisions
-
minus7 created this gist
May 8, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ #!/usr/bin/env python3 # vim: set noexpandtab: from functools import wraps from inspect import signature def type_checked(func): @wraps(func) def wrapper(*args, **kwargs): sig = signature(func) bound = sig.bind(*args, **kwargs) for k,v in bound.arguments.items(): ann = sig.parameters[k].annotation if ann and not isinstance(v, ann): raise ValueError("Argument {} should be of type {}, is {}" .format(k, ann, type(v))) return func(*bound.args, **bound.kwargs) return wrapper