Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Bare bones type checking for function
from functools import wraps
class Boat(object):
def __init__(self,color):
self.color = color
def hello(self):
print("I'm a {} boat".format(self.color))
def arg_check(typelist):
def decorator(f):
def wrapper(*args, **kwds):
for ii, typeitem in enumerate(typelist):
"{} is not {} for {}".format(args[ii] , typeitem[1],f)
return f(*args, **kwds)
return wrapper
return decorator
def silly(myarg1,myarg2,boat):
print("I'm done")
if __name__ == "__main__":
print("HELLO WORLD")
yacht = Boat("gray")
silly("gravy",3,"not a boat")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment