-
Notifications
You must be signed in to change notification settings - Fork 1
fix(oocana): extract _wrap_output_with_warning to reduce duplication #454
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
base: main
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 |
|---|---|---|
|
|
@@ -434,6 +434,23 @@ async def oomol_token(self) -> str: | |
| """ | ||
| return os.getenv("OOMOL_TOKEN", "") | ||
|
|
||
| def _wrap_output_with_warning(self, key: str, value: Any) -> tuple[Any, bool]: | ||
| """ | ||
| Wrap output value with error handling. | ||
|
|
||
| Args: | ||
| key: The output handle key | ||
| value: The value to wrap | ||
|
|
||
| Returns: | ||
| A tuple of (wrapped_value, success). If success is False, wrapped_value is None. | ||
| """ | ||
| try: | ||
| return self.__wrap_output_value(key, value), True | ||
| except (ValueError, IOError) as e: | ||
| self.send_warning(f"{e}") | ||
| return None, False | ||
|
Comment on lines
+437
to
+452
|
||
|
|
||
| def output(self, key: str, value: Any, *, to_node: list[ToNode] | None = None, to_flow: list[ToFlow] | None = None): | ||
| """ | ||
| output the value to the next block | ||
|
|
@@ -444,57 +461,35 @@ def output(self, key: str, value: Any, *, to_node: list[ToNode] | None = None, t | |
| :param to_flow: list[ToFlow] | None, the target flow(with output handle) to send the output | ||
| if both to_node and to_flow are None, the output will be sent to all connected nodes and flows. | ||
| """ | ||
|
|
||
| try: | ||
| wrap_value = self.__wrap_output_value(key, value) | ||
| except ValueError as e: | ||
| self.send_warning( | ||
| f"{e}" | ||
| ) | ||
| return | ||
| except IOError as e: | ||
| self.send_warning( | ||
| f"{e}" | ||
| ) | ||
| wrap_value, success = self._wrap_output_with_warning(key, value) | ||
| if not success: | ||
| return | ||
|
|
||
| target = None | ||
| if to_node is not None or to_flow is not None: | ||
| target = { | ||
| "to_node": to_node, | ||
| "to_flow": to_flow, | ||
| } | ||
| else: | ||
| target = None | ||
| target = {"to_node": to_node, "to_flow": to_flow} | ||
|
|
||
| payload = { | ||
| payload: Dict[str, Any] = { | ||
| "type": "BlockOutput", | ||
| "handle": key, | ||
| "output": wrap_value, | ||
| } | ||
| if target is not None: | ||
| payload["options"] = {"target": target} | ||
| self.__mainframe.send(self.job_info, payload) | ||
|
|
||
| def outputs(self, outputs: Dict[str, Any]): | ||
| """ | ||
| output the value to the next block | ||
|
|
||
| map: Dict[str, Any], the key of the output, should be defined in the block schema output defs, the field name is handle | ||
| """ | ||
|
|
||
| values = {} | ||
| for key, value in outputs.items(): | ||
| try: | ||
| wrap_value = self.__wrap_output_value(key, value) | ||
| wrap_value, success = self._wrap_output_with_warning(key, value) | ||
| if success: | ||
| values[key] = wrap_value | ||
| except ValueError as e: | ||
| self.send_warning( | ||
| f"{e}" | ||
| ) | ||
| except IOError as e: | ||
| self.send_warning( | ||
| f"{e}" | ||
| ) | ||
|
|
||
| self.__mainframe.send(self.job_info, { | ||
| "type": "BlockOutputs", | ||
| "outputs": values, | ||
|
|
||
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.
For consistency with other helper methods in the Context class (such as __wrap_output_value, __is_basic_type, __store_ref, __dataframe, __matplotlib), this method should use double underscores (__wrap_output_with_warning) rather than a single underscore to indicate it's a private method.