Skip to content

Instantly share code, notes, and snippets.

@urbanonymous
Created June 17, 2019 18:29
Show Gist options
  • Save urbanonymous/e6b21e473d0d9d40a42f8fdba7d73f1d to your computer and use it in GitHub Desktop.
Save urbanonymous/e6b21e473d0d9d40a42f8fdba7d73f1d to your computer and use it in GitHub Desktop.
Checks that you only pass one argument to a full keyword optional arguments method
import inspect
def task(id_a=False, id_b=False, name=False, email=False, phone=False):
frame = inspect.currentframe()
args, _, _, values = inspect.getargvalues(frame)
if len([arg for arg in args if values[arg]]) != 1: # Checks that you only pass one argument
raise ValueError("Need only one argument")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment