Skip to content
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

fixed len_output method does not support handler-defined logic issue #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

koussayinsat12
Copy link

@koussayinsat12 koussayinsat12 commented Jan 25, 2025

This pull request refactors the len_output method in the workflow implementation to address inconsistencies in how output lengths are calculated. Previously, the method directly computed the length of self.current_output, ignoring handler-defined logic. This caused issues when custom handlers redefined the logic for determining output length.

The updated implementation now leverages the corresponding handler to calculate the length of the output, ensuring consistency across workflows.

Key Changes:

1.Delegation to Handlers:

  • The method now retrieves the appropriate handler using self.workflow.handlers and delegates the length calculation to handler.len_output(output).

2.Flexible Output Selection:

  • Added an output parameter (default: -1) to specify which output to evaluate, making the method more versatile for workflows with multiple outputs.

3.Improved Readability and Maintenance:

  • Introduced type hints (int | None) and a detailed docstring for better code clarity and usability.

@zeddo123 zeddo123 added the enhancement New feature or request label Jan 26, 2025
Copy link
Member

@zeddo123 zeddo123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @koussayinsat12 for your contribution! There's a single think to take care of and then we'll merge this PR.

handler = self.workflow.handlers[output]
output = self.outputs[output]

return handler.len_output(output) if hasattr(output, '__len__') else None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the if statement is necessary anymore since the handler would take care of any underlying logic.

Copy link
Author

@koussayinsat12 koussayinsat12 Jan 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the statement if, because the DefaultHandler returns len of the output and when the output is not the type of variable that we can't calculate its length, it returns None. If we remove the if statement, the tests of the workflow will fail

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have deleted the if statement inside the workflow and integrate it inside the handlers

@zeddo123 zeddo123 linked an issue Jan 26, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

len_output Method Does Not Use Handler-Defined Logic
2 participants