Check for __kwarg__ using get instead of pop and then skip __kwarg__ during the loop.

This commit is contained in:
Gareth J. Greenaway 2023-09-13 11:43:23 -07:00 committed by Megan Wilhite
parent f2511ff711
commit 88700f894d

View file

@ -327,9 +327,12 @@ def load_args_and_kwargs(func, args, data=None, ignore_invalid=False):
invalid_kwargs = []
for arg in args:
if isinstance(arg, dict) and arg.pop("__kwarg__", False) is True:
if isinstance(arg, dict) and arg.get("__kwarg__", False) is True:
# if the arg is a dict with __kwarg__ == True, then its a kwarg
for key, val in arg.items():
# Skip __kwarg__ when checking kwargs
if key == "__kwarg__":
continue
if argspec.keywords or key in argspec.args:
# Function supports **kwargs or is a positional argument to
# the function.
@ -339,7 +342,6 @@ def load_args_and_kwargs(func, args, data=None, ignore_invalid=False):
# list of positional arguments. This keyword argument is
# invalid.
invalid_kwargs.append("{}={}".format(key, val))
arg.update({"__kwarg__": True})
continue
else: