Skip to content

Allow Node.unlink() to clear all children when called with no arguments#79

Merged
ConnorStoneAstro merged 6 commits intodevfrom
copilot/add-unlink-all-children-functionality
Mar 6, 2026
Merged

Allow Node.unlink() to clear all children when called with no arguments#79
ConnorStoneAstro merged 6 commits intodevfrom
copilot/add-unlink-all-children-functionality

Conversation

Copy link

Copilot AI commented Mar 3, 2026

Node.unlink() required a key argument; calling it with no arguments raised a TypeError instead of acting as a convenient "clear all children" operation.

Changes

  • Node.unlink()key is now optional (defaults to None); when omitted, all children are unlinked by delegating to self.unlink(list(self.children)), following the same list/tuple recursive path so __delattr__ is called appropriately for each child
  • Docstring — added Parameters section documenting all call signatures including the no-arg form
  • Tests — added assertion in test_linking covering the no-arg case
  • BeginnersGuide notebook — added a "Linking and unlinking params" subsection at the bottom of "The pointer parameter" section with a concise demo of link(key, node), unlink(key), and unlink() (clear all)

Usage

a = Node("a")
b = Node("b")
c = Node("c")
a.link(b)
a.link(c)

a.unlink()          # removes all children at once
assert len(a.children) == 0
Original prompt

This section details on the original issue you should resolve

<issue_title>Calling unlink with no arguments should simply unlink all children</issue_title>
<issue_description>If I call node.unlink() it should just clear all linked children that the node has. This would be very convenient as a type of clear function.

The capability would also need to be indicated in the docstring for unlink. Added to the beginner tutorial notebook alongside examples for linking/unlinking. And checked in the unit tests.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: ConnorStoneAstro <78555321+ConnorStoneAstro@users.noreply.github.com>
Copilot AI changed the title [WIP] Add unlink method to clear all linked children Allow Node.unlink() to clear all children when called with no arguments Mar 3, 2026
@ConnorStoneAstro
Copy link
Owner

@copilot In the beginners tutorial can you place the unlink discussion at the bottom of the The pointer parameter section? Make it something like link/unlink params and demo how linking works in general (though concisely)

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>
Copy link
Author

Copilot AI commented Mar 3, 2026

@copilot In the beginners tutorial can you place the unlink discussion at the bottom of the The pointer parameter section? Make it something like link/unlink params and demo how ...

Done in 21027bc. Two changes:

  1. Code: The no-arg path now delegates to self.unlink(list(self.children)), so it goes through the existing list/tuple recursive path and calls __delattr__ for each child (same as passing a list of keys).

  2. Notebook: Removed the "Unlinking nodes" cells that were after the functional pointers example. Added a new "### Linking and unlinking params" section at the bottom of "The pointer parameter" section (before "## Nested Modules"), with a concise self-contained demo showing link(key, node), unlink(key), and unlink() (clear all).

@codecov
Copy link

codecov bot commented Mar 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (55c32e9) to head (dea816e).
⚠️ Report is 1 commits behind head on dev.

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     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ConnorStoneAstro ConnorStoneAstro marked this pull request as ready for review March 3, 2026 16:06
Copilot AI review requested due to automatic review settings March 3, 2026 16:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 optional key (defaulting to None) and treat unlink() 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 key is a Node and it is not found among self.children.values(), key remains a Node instance and the method will eventually call __delattr__(key), which raises a TypeError (attribute name must be a string). Consider tracking whether a match was found and raising a clear GraphError/KeyError when 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.

Copy link
Owner

@ConnorStoneAstro ConnorStoneAstro left a comment

Choose a reason for hiding this comment

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

This looks great!

@ConnorStoneAstro ConnorStoneAstro changed the base branch from main to dev March 4, 2026 20:43
@ConnorStoneAstro ConnorStoneAstro merged commit 2d996ab into dev Mar 6, 2026
33 checks passed
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.

Calling unlink with no arguments should simply unlink all children

3 participants