Skip to content

Fix #71 isolated isntance properties from class properties#110

Merged
cjtu merged 1 commit into
mainfrom
71-fix-roi-attr-leak
Jun 19, 2026
Merged

Fix #71 isolated isntance properties from class properties#110
cjtu merged 1 commit into
mainfrom
71-fix-roi-attr-leak

Conversation

@cjtu

@cjtu cjtu commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Problem

ROIs added via add_annuli/add_circles were registered as property objects on the class (setattr(self.class, ...)), not the instance. As a result, an ROI added to one CraterDatabase appeared on every instance — its name showed up in the repr but accessing it raised KeyError because the column only existed in the originatin

a = CraterDatabase(crater_list, 'moon
b = CraterDatabase(crater_list, 'moon')
a.add_annuli('new', 1, 3)
print(b) # ...includes "new" ← wrong
b.new # KeyError ←

Fix

Track ROIs per-instance instead of polluting the class:

  • New self._roi_names dict (attr name → data column) populated by _make_data_property.
  • getattr resolves registered ROInames to self.data column, preserving the convenient cdb.ejecta access and raising a proper AttributeError for unknown names. It reads _roi_names via self.dict to avoid recursion before init sets it (also safe under deepcopy/copy).
  • _get_properties/repr now combine the static class properties with the instance's own ROIs.

After the fix, b no longer reports or exposes new, and b.new raises AttributeError.

Tests

  • Added test_roi_attrs_are_per_instance: adds an ROI to one copy and asserts it's present on that instance but absent from another's repr and raises AttributeError on access.

Other

  • Version bump 0.11.2 → 0.11.3 (+ uv.lock sync).

Closes #71

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.99%. Comparing base (a04a81c) to head (ff219df).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #110      +/-   ##
==========================================
+ Coverage   96.95%   96.99%   +0.04%     
==========================================
  Files           4        4              
  Lines         525      532       +7     
  Branches       75       76       +1     
==========================================
+ Hits          509      516       +7     
  Misses          8        8              
  Partials        8        8              

☔ View full report in Codecov by Harness.
📢 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.

@cjtu cjtu merged commit edeb310 into main Jun 19, 2026
9 checks passed
@cjtu cjtu deleted the 71-fix-roi-attr-leak branch June 19, 2026 16:11
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.

Bug: repr shows attr from other craterdatabase

1 participant