Created
June 17, 2019 18:29
-
-
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
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
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