Skip to content

Instantly share code, notes, and snippets.

@geekyarthurs
Created December 2, 2020 12:27
Show Gist options
  • Save geekyarthurs/6b506a81ecb086739e0a139c42a4d976 to your computer and use it in GitHub Desktop.
Save geekyarthurs/6b506a81ecb086739e0a139c42a4d976 to your computer and use it in GitHub Desktop.
#/bin/env python
from typing import Callable
def decorator(function: Callable):
def inner_function(*args, **kwargs):
newKwargs = {}
for argName, typeName in function.__annotations__.items():
if typeName is int:
intVar = int(kwargs[argName])
newKwargs[argName] = intVar
elif typeName is str:
strVar = str(kwargs[argName])
newKwargs[argName] = strVar
function(*args, **newKwargs)
return inner_function
@decorator
def getAge(age: int, name: str):
print( f" {age} : {type(age)} , {name} : {type(name)} " )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment