Skip to content

Commit

Permalink
Support the unpack operator in signature (apache#41316)
Browse files Browse the repository at this point in the history
Co-authored-by: Tzu-ping Chung <[email protected]>
Co-authored-by: jabbera <[email protected]>
Co-authored-by: jabbera <[email protected]>
  • Loading branch information
4 people authored Aug 30, 2024
1 parent feee981 commit 6e01118
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion airflow/utils/operator_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ def determine(
signature = inspect.signature(func)
has_wildcard_kwargs = any(p.kind == p.VAR_KEYWORD for p in signature.parameters.values())

for name in itertools.islice(signature.parameters.keys(), len(args)):
for name, param in itertools.islice(signature.parameters.items(), len(args)):
# Keyword-only arguments can't be passed positionally and are not checked.
if param.kind == inspect.Parameter.KEYWORD_ONLY:
continue
if param.kind == inspect.Parameter.VAR_KEYWORD:
continue

# Check if args conflict with names in kwargs.
if name in kwargs:
raise ValueError(f"The key {name!r} in args is a part of kwargs and therefore reserved.")
Expand Down
12 changes: 12 additions & 0 deletions tests/utils/test_operator_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,15 @@ def func(ds_nodash):
kwargs_callable(*args, **kwargs)

assert "ds_nodash" in str(exc_info)


@pytest.mark.parametrize(
"func,args,kwargs,expected",
[
(callable10, (1, 2), {"ds_nodash": 1}, {"ds_nodash": 1}),
(callable11, (1, 2), {"ds_nodash": 1}, {"ds_nodash": 1}),
],
)
def test_args_and_kwargs_conflicts(func, args, kwargs, expected):
kwargs_result = operator_helpers.determine_kwargs(func, args=args, kwargs=kwargs)
assert expected == kwargs_result

0 comments on commit 6e01118

Please sign in to comment.