Skip to content

Instantly share code, notes, and snippets.

@AnkDos
Last active October 8, 2020 18:57
Show Gist options
  • Save AnkDos/37bbccc10003415a0e1f9dd0495a44ca to your computer and use it in GitHub Desktop.
Save AnkDos/37bbccc10003415a0e1f9dd0495a44ca to your computer and use it in GitHub Desktop.
#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