multiple return keys for tuple returning functions#107
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the pipeline_node decorator to support mapping multi-value (tuple) returns into multiple keys in the pipeline datablock, via a new reserved kwarg return_keys (in addition to return_key).
Changes:
- Add
return_keysas a reserved kwarg name forpipeline_node-decorated functions. - Allow passing
return_keysto write tuple-return outputs into multiple datablock keys. - Keep backward-compatibility intent by falling back to
return_keywhenreturn_keysis not provided.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
agrifoodpy/pipeline/pipeline.py:479
- The reserved-parameter ValueError message is missing spaces due to implicit string concatenation, which makes the exception hard to read (e.g., ".Please rename..." and "thepipeline_node"). Consider formatting it as a single, well-spaced message (optionally factoring out the reserved params set) for clarity.
if reserved & set(signature(func).parameters):
raise ValueError(f"Function {func.__name__} has reserved parameter"
f" names {reserved & set(signature(func).parameters)}."
"Please rename these parameters to use the"
"pipeline_node decorator.")
Comment on lines
426
to
+430
| input_keys = [] | ||
|
|
||
| def pipeline_decorator(func): | ||
| reserved = {"datablock", "return_key"} | ||
|
|
||
| def normalize_return_keys(return_keys): |
Comment on lines
+506
to
+510
| return_keys = kwargs.pop("return_keys", None) | ||
| return_key = kwargs.pop("return_key", None) | ||
|
|
||
| if return_keys is None and return_key is not None: | ||
| return_keys = return_key |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adjusts the behaviour of the
pipeline_nodedecorator to allow functions returning multiple values to store their outputs in multiple keys of the datablock simultaneouslyThe decorator has two reserved keywords:
return_keyandreturn_keyswhich can only be used to identify the datablock path where results should be stored and cannot be used as part of the function signature.Checklist