Last active
October 8, 2020 18:57
-
-
Save AnkDos/37bbccc10003415a0e1f9dd0495a44ca 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
#Created By AnkDos(https://github.com/AnkDos) | |
#A decorator to validate function argument | |
def validate_inputs(func): | |
def validate(*args): | |
variables_value_map = dict(zip(func.__code__.co_varnames,args)) | |
for key, value in func.__annotations__.items(): | |
assert isinstance(variables_value_map[key],value),\ | |
'Invalid Attribute' | |
return func(*args) | |
return validate | |
@validate_inputs | |
def val(a:str, | |
b:(int,type(None)), | |
c: list, | |
d: dict, | |
e: type(None), | |
f: (float,list), | |
g: int | |
): | |
pass | |
@validate_inputs | |
def some_other_method(inp:int): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment