-
Notifications
You must be signed in to change notification settings - Fork 914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unpack dictionary parameters #3905
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,8 @@ def __init__( # noqa: PLR0913 | |
_node_error_message("it must have some 'inputs' or 'outputs'.") | ||
) | ||
|
||
inputs = _unpacked_params(func, inputs) | ||
|
||
self._validate_inputs(func, inputs) | ||
|
||
self._func = func | ||
|
@@ -683,3 +685,31 @@ def _get_readable_func_name(func: Callable) -> str: | |
name = "<partial>" | ||
|
||
return name | ||
|
||
|
||
def _unpacked_params( | ||
func: Callable, inputs: None | str | list[str] | dict[str, str] | ||
) -> None | str | list[str] | dict[str, str]: | ||
"""Iterate over Node inputs to see if they need to be unpacked. | ||
|
||
Returns: | ||
Either original inputs if no input was unpacked or a list of inputs if an input was unpacked. | ||
""" | ||
use_new = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest renaming it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we please rename it? |
||
new_inputs = [] | ||
_func_arguments = [arg for arg in inspect.signature(func).parameters] | ||
for idx, _input in enumerate(_to_list(inputs)): | ||
if _input.startswith("**params"): | ||
if "**" in str(inspect.signature(func)): | ||
raise TypeError( | ||
"Function side dictionary unpacking is currently incompatible with parameter dictionary unpacking." | ||
) | ||
use_new = True | ||
dict_root = _input.split(":")[-1] | ||
for param in _func_arguments[idx:]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of slicing the list, we can just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand what you're recommending. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
new_inputs.append(f"params:{dict_root}.{param}") | ||
else: | ||
new_inputs.append(_input) | ||
if use_new: | ||
return new_inputs | ||
return inputs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.