Repository navigation
Conversation
wrapt.ObjectProxy exposes __iter__ at the C level, so a scalar TaggedValue reported isinstance(_, Iterable) as True while iter() raised TypeError — a contradiction that broke any ABC-based isinstance check downstream (e.g. AiiDA's clean_value). TaggedValue.__new__ now dispatches on the wrapped value's actual iterability, returning a _TaggedScalar (with __iter__ = None, which the Iterable subclass hook reads as "intentionally unset") for non-iterables and a _TaggedIterable otherwise. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #177 +/- ##
==========================================
+ Coverage 89.68% 89.71% +0.03%
==========================================
Files 81 81
Lines 8984 9021 +37
==========================================
+ Hits 8057 8093 +36
- Misses 927 928 +1 ☔ View full report in Codecov by Harness. 🚀 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.
Problem
TaggedValue(thewrapt.ObjectProxynode-graph wraps a socket's value in) always exposed__iter__, becausewrapt.ObjectProxyforwards every dunder at the C level regardless of what it wraps. That madeisinstance(TaggedValue(1.5), collections.abc.Iterable)reportTruefor a wrapped scalar, even though actually callingiter(...)on it raisedTypeError.This PR closes the Iterable-masquerade itself, for every wrapped scalar; whether that alone makes a given wrapped value pass
clean_valuedepends on what else that function checks.In practice a wrapped
float/intbecomes storable, but a wrappedboolstill returns the proxy (boolcan't be subclassed, soisinstance(TaggedValue(True), bool)staysFalse) and a wrappedNonestill fails validation (value is Nonedoesn't hold for the proxy) — both known residuals this PR does not resolve.Changes
TaggedValue.__new__now dispatches on the wrapped value's actual iterability, returning a_TaggedScalar(which shadows__iter__withNone) for non-iterables and a_TaggedIterable(which inherits the proxy's forwarding__iter__) otherwise. Python'sIterable.__subclasshook__treats__iter__ = Noneas "intentionally unset" and answersFalse.TaggedValuebehaviour: arithmetic, equality, thesocket=kwarg, copy/deepcopy, and serialization all still forward through the wrapped value exactly as before.Testing
TestTaggedValueIterable(tests/test_socket.py): a wrapped scalar (float,int,complex,None,bool) is notIterableand raisesTypeErroroniter(), while still proxying arithmetic and equality; a wrappedlist/tuple/dict/str/setisIterableand iterates to the same elements as the unwrapped value; thesocket=kwarg survives dispatch on both branches.__new__dispatch while keeping the new tests fails 2 of them (test_scalar_is_not_iterable,test_socket_kwarg_preserved_on_scalar_and_iterable) — confirming the tests exercise the fix, not something already true beforehand.