-
Notifications
You must be signed in to change notification settings - Fork 189
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
Conversation
f061d1e
to
8b63baf
Compare
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Great work! Can you also add an example that shows how a user might use the new imperative methods?
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 | ||
|
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.
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?
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.
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
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.
I'm sold, thanks for explaining!
6d28983
to
40eb047
Compare
ea086fb
to
0b5bffc
Compare
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.
Great work! So much better.
0b5bffc
to
bc924df
Compare
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()
andActionSubTask.add_parent()
due to effectively no change in behavior. The behavior ofActionSubTask.add_child()
andActionSubTask.add_parent()
has been moved up the hierarchy intoBaseTask
and changed to only define relationships asymmetrically in order to be consistent with the approach of passing parent or child ids intoBaseTask()
. This change in behavior required one update toToolKitTask.add_subtask
to invoke bothadd_child
andadd_parent
sinceStructure.resolve_relationships()
only effects tasks that have been added toStructure
directly (which does not include sub tasks.📚 Documentation preview 📚: https://griptape--822.org.readthedocs.build//822/