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

Add task relationship APIs #822

Merged
merged 3 commits into from
Jun 5, 2024
Merged

Conversation

dylanholmes
Copy link
Contributor

@dylanholmes dylanholmes commented Jun 4, 2024

See CHANGLOG.md for the majority of changes and docs + unit tests for example usages.

One change not listed in the change log is the removal of ActionSubTask.add_child() and ActionSubTask.add_parent() due to effectively no change in behavior. The behavior of ActionSubTask.add_child() and ActionSubTask.add_parent() has been moved up the hierarchy into BaseTask and changed to only define relationships asymmetrically in order to be consistent with the approach of passing parent or child ids into BaseTask(). This change in behavior required one update to ToolKitTask.add_subtask to invoke both add_child and add_parent since Structure.resolve_relationships() only effects tasks that have been added to Structure directly (which does not include sub tasks.


📚 Documentation preview 📚: https://griptape--822.org.readthedocs.build//822/

@dylanholmes dylanholmes force-pushed the feature/task-relationship-apis branch 2 times, most recently from f061d1e to 8b63baf Compare June 4, 2024 10:21
Copy link

codecov bot commented Jun 4, 2024

Codecov Report

Attention: Patch coverage is 94.28571% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
griptape/tasks/base_task.py 85.71% 0 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@dylanholmes dylanholmes marked this pull request as ready for review June 4, 2024 10:42
@dylanholmes dylanholmes requested a review from collindutter June 4, 2024 10:42
Copy link
Member

@collindutter collindutter left a comment

Choose a reason for hiding this comment

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

Great work! Can you also add an example that shows how a user might use the new imperative methods?

griptape/tasks/base_task.py Outdated Show resolved Hide resolved
griptape/tasks/base_task.py Outdated Show resolved Hide resolved
Comment on lines -175 to -192
def add_child(self, child: ActionsSubtask) -> ActionsSubtask:
if child.id not in self.child_ids:
self.child_ids.append(child.id)

if self.id not in child.parent_ids:
child.parent_ids.append(self.id)

return child

def add_parent(self, parent: ActionsSubtask) -> ActionsSubtask:
if parent.id not in self.parent_ids:
self.parent_ids.append(parent.id)

if self.id not in parent.child_ids:
parent.child_ids.append(self.id)

return parent

Copy link
Member

Choose a reason for hiding this comment

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

Is this necessary to remove? I understand it's for consistency, but isn't that what overriding methods is good for? Changing behavior in subclasses?

Copy link
Contributor Author

@dylanholmes dylanholmes Jun 5, 2024

Choose a reason for hiding this comment

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

Its not necessary to remove. I just thought it makes the logic easier to reason about.

I agree that overriding is for changing behavior in subclasses, but it can be abused. It seems unintuitive to change mutate objects passed in as arguments in a subclass only.

As an extreme example, imagine a class that has a method called sort which returns a list. It would be pretty strange if the base class returned a new list in sorted order, but a subclass sorted in-place and returned a reference to the same list.

That said, this case is not nearly that extreme, and I don't have the strongest opinion. I just gave the example as the intuition behind my position.

Let me know if this changes your opinion at all. I'll gladly revert if you prefer

Copy link
Member

Choose a reason for hiding this comment

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

I'm sold, thanks for explaining!

@dylanholmes dylanholmes force-pushed the feature/task-relationship-apis branch 3 times, most recently from 6d28983 to 40eb047 Compare June 5, 2024 09:53
@dylanholmes dylanholmes requested a review from collindutter June 5, 2024 09:59
@collindutter collindutter force-pushed the feature/task-relationship-apis branch from ea086fb to 0b5bffc Compare June 5, 2024 16:42
Copy link
Member

@collindutter collindutter left a comment

Choose a reason for hiding this comment

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

Great work! So much better.

@collindutter collindutter force-pushed the feature/task-relationship-apis branch from 0b5bffc to bc924df Compare June 5, 2024 16:46
@dylanholmes dylanholmes merged commit 8630317 into dev Jun 5, 2024
10 checks passed
@dylanholmes dylanholmes deleted the feature/task-relationship-apis branch June 5, 2024 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants