Allow Node.unlink() to clear all children when called with no arguments#79
Conversation
Co-authored-by: ConnorStoneAstro <78555321+ConnorStoneAstro@users.noreply.github.com>
Node.unlink() to clear all children when called with no arguments
|
@copilot In the beginners tutorial can you place the unlink discussion at the bottom of the Also the unlink all children option should work like the list/tuple option and recursively call with the children keys. That way the del method will be called appropriately. |
Co-authored-by: ConnorStoneAstro <78555321+ConnorStoneAstro@users.noreply.github.com>
Done in 21027bc. Two changes:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #79 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 13 13
Lines 1688 1694 +6
=========================================
+ Hits 1688 1694 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR enhances the Node.unlink() API to support a convenient no-argument call that unlinks (clears) all current children, and updates documentation and examples accordingly.
Changes:
- Make
Node.unlink()accept an optionalkey(defaulting toNone) and treatunlink()as “unlink all children”. - Expand the
Node.unlink()docstring to document the supported call signatures. - Add test coverage for the new no-arg
unlink()behavior and update the BeginnersGuide notebook with a linking/unlinking demo.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/caskade/base.py |
Updates Node.unlink() signature/behavior and documents the new no-arg form. |
tests/test_base.py |
Adds an assertion that unlink() clears all children. |
docs/source/notebooks/BeginnersGuide.ipynb |
Adds a short tutorial subsection demonstrating link(...), unlink(key), and unlink() clearing all children. |
Comments suppressed due to low confidence (1)
src/caskade/base.py:229
- When
keyis aNodeand it is not found amongself.children.values(),keyremains aNodeinstance and the method will eventually call__delattr__(key), which raises aTypeError(attribute name must be a string). Consider tracking whether a match was found and raising a clearGraphError/KeyErrorwhen the passed node is not a child, instead of falling through to__delattr__.
if isinstance(key, Node):
for node in self.children:
if self.children[node] is key:
key = node
break
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Node.unlink()required akeyargument; calling it with no arguments raised aTypeErrorinstead of acting as a convenient "clear all children" operation.Changes
Node.unlink()—keyis now optional (defaults toNone); when omitted, all children are unlinked by delegating toself.unlink(list(self.children)), following the same list/tuple recursive path so__delattr__is called appropriately for each childParameterssection documenting all call signatures including the no-arg formtest_linkingcovering the no-arg casepointerparameter" section with a concise demo oflink(key, node),unlink(key), andunlink()(clear all)Usage
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.