fix: only proxy actual stats through Hypergraph.__getattr__ (#408)#736
Open
leotrs wants to merge 1 commit into
Open
fix: only proxy actual stats through Hypergraph.__getattr__ (#408)#736leotrs wants to merge 1 commit into
leotrs wants to merge 1 commit into
Conversation
Hypergraph.__getattr__ (and DiHypergraph.__getattr__) blindly delegated every attribute lookup to the underlying views, wrapping whatever it found and calling .asdict() on the result. That works for actual stats but produces confusing errors for view methods like filterby, neighbors, memberships, isolates, singletons, empty, etc. Tighten the check from `stat is None` to `not isinstance(stat, IDStat)` so only true stat objects are proxied. Non-stat view methods now raise AttributeError as they should. Tested with built-in and user-defined (@nodestat_func / @dinodestat_func) stats still accessible, and a list of common non-stat view methods now correctly inaccessible via H. / DH. Closes #408 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #736 +/- ##
==========================================
+ Coverage 93.65% 94.63% +0.97%
==========================================
Files 66 66
Lines 5168 5290 +122
==========================================
+ Hits 4840 5006 +166
+ Misses 328 284 -44 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #408.
Hypergraph.__getattr__(andDiHypergraph.__getattr__) blindly delegated every attribute lookup to the underlying views and wrapped whatever it found in a function that calls.asdict(). That works for actual stats but produces confusing errors when users hit view methods that happen to share a name with no stat:Fix
Tighten the delegation check from
stat is Nonetonot isinstance(stat, IDStat). Built-in stats (registered via_stat_property) and user-defined stats (via@nodestat_funcetc.) both returnIDStatinstances, so they continue to work. Non-stat view methods (filterby,neighbors,memberships,isolates,singletons,empty,members,dimembers,head,tail, ...) now correctly raiseAttributeErrorat lookup time with the existing helpful message.Same one-line change in both
HypergraphandDiHypergraph.Safety check: grepped
xgi/,tests/, andtutorials/forH.filterby(,H.neighbors(,H.memberships(, etc. — zero hits. Nothing in the repo relied on the broken proxies.Test plan
test_getattr_only_proxies_statsfor bothHypergraphandDiHypergraph) covering: built-in stats still work, user-defined stats still work, every non-stat view method raisesAttributeError, unknown attributes raiseAttributeError