Created
December 2, 2020 12:27
-
-
Save geekyarthurs/6b506a81ecb086739e0a139c42a4d976 to your computer and use it in GitHub Desktop.
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 characters
#/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