Skip to content

Fix missing methods on proxies#31

Merged
berendkleinhaneveld merged 11 commits intomasterfrom
fix-proxy-missing-methods
Mar 17, 2026
Merged

Fix missing methods on proxies#31
berendkleinhaneveld merged 11 commits intomasterfrom
fix-proxy-missing-methods

Conversation

@berendkleinhaneveld
Copy link
Collaborator

@berendkleinhaneveld berendkleinhaneveld commented Mar 16, 2026

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.

berendkleinhaneveld and others added 9 commits March 16, 2026 21:41
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>
@berendkleinhaneveld
Copy link
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 berendkleinhaneveld merged commit c0aea5f into master Mar 17, 2026
10 checks passed
@berendkleinhaneveld berendkleinhaneveld deleted the fix-proxy-missing-methods branch March 17, 2026 08:25
berendkleinhaneveld added a commit that referenced this pull request Mar 17, 2026
This release includes the following:
- Fix missing methods on proxies (#31)
berendkleinhaneveld added a commit that referenced this pull request Mar 17, 2026
This release includes the following:

- Fix missing methods on proxies (#31)
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.

1 participant