Skip to content

Instantly share code, notes, and snippets.

@scidam
Created November 8, 2021 15:59
Show Gist options
  • Select an option

  • Save scidam/290d877d9c940fe5f933b104bcfde143 to your computer and use it in GitHub Desktop.

Select an option

Save scidam/290d877d9c940fe5f933b104bcfde143 to your computer and use it in GitHub Desktop.
My solution (as is) to arg_checker challenge
from functools import wraps
def arg_checker(*arg_types):
'''An argument checker decorator that checks both:
- The number of variables that you use for a function
- The type of each variable.
Raises a TypeError if either of these fail'''
def wrapper(func):
@wraps(func)
def wrapped(*args):
if any(not isinstance(a, at) for a, at in zip(args, at))\
or len(arg_types) != len(args):
raise TypeError("Hello, there is a type error with arguments")
return func(*args)
return wrapped
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment