Fix missing methods on proxies#31
Merged
berendkleinhaneveld merged 11 commits intomasterfrom Mar 17, 2026
Merged
Conversation
DictProxy: - values() and items() now return proxied nested objects (was broken: iterating values/items of dicts with nested containers didn't track mutations) - Add __ior__ (|=), __or__ (|), __ror__, __eq__, __ne__, __bool__ ListProxy: - __iter__ and __reversed__ now return proxied nested objects (was broken: for-loop over lists with nested containers didn't track mutations) - Add __iadd__ (+=), __imul__ (*=), __add__ (+), __radd__, __mul__ (*), __rmul__, __eq__, __ne__, __lt__, __le__, __gt__, __ge__, __bool__ SetProxy: - Add difference_update, intersection_update, symmetric_difference_update - Add __or__ (|), __ror__, __and__ (&), __rand__, __sub__ (-), __rsub__, __xor__ (^), __rxor__, __eq__, __ne__, __le__, __lt__, __ge__, __gt__, __bool__ All proxies: add __str__ and __format__ as reader pass-throughs. Add comments documenting skipped methods and why. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
__eq__, __ne__, and comparison dunders work fine via _add_reader_methods since it uses setattr on the class. __bool__ is not needed since Python falls back to __len__ for truthiness, and __len__ is already proxied. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Since __eq__ is added via setattr (not in the class body), Python doesn't automatically set __hash__ = None. Set it explicitly on all three proxy classes so they're unhashable like the types they proxy. Also remove __radd__ from ListProxy — list doesn't support reverse add. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace explicit one-liner delegations with _add_reader_methods entries: - DictProxy: __or__, __ror__ - ListProxy: __add__, __mul__, __rmul__ - SetProxy: __or__, __ror__, __and__, __rand__, __sub__, __rsub__, __xor__, __rxor__ Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- DictProxy.pop(): test that popping a key with a cached proxy invalidates it - DictProxy.popitem(): same for popitem - ListProxy.__imul__: test *= 0 (clears the list) produce.py is now at 100% coverage. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Tests compare dir(Proxy) against dir(base_type) and fail if a method exists on the base type that isn't on the proxy and isn't in the explicit SKIPPED set. This catches new methods added in future Python versions. Skipped entries that don't apply to a given Python version are silently ignored, so the tests work across Python 3.9-3.14. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Move DictProxy/ListProxy/SetProxy import to top of file (E402) - Convert class attributes to module-level constants (RUF012) - Prefix unused `result` variables with underscore (RUF059) - Add noqa for intentional list concatenation in operator test (RUF005) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
Author
|
I tried this out in the project where I had some trouble before and it works great now! Will merge and push out a new version soon. |
berendkleinhaneveld
added a commit
that referenced
this pull request
Mar 17, 2026
This release includes the following: - Fix missing methods on proxies (#31)
Merged
berendkleinhaneveld
added a commit
that referenced
this pull request
Mar 17, 2026
This release includes the following: - Fix missing methods on proxies (#31)
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.
I noticed some problems producing patches because of missing implementations of proxy methods.
Now all methods should be covered. The test suite also now checks for an expected list of supported (and unsupported) methods.
And restore 100% code coverage.