Repository navigation
Serve class-defined rx attributes without resolving the node - #1230
Open
philippjfr wants to merge 1 commit into
Open
philippjfr wants to merge 1 commit into
philippjfr wants to merge 1 commit into
Conversation
rx.__getattribute__ resolved a dirty node, or returned a lazy getattr clone, before checking whether the name was defined on the class. A property or method on an rx subclass therefore forced a compute just to be read, and hasattr() did too. Class-defined names now short-circuit after the disposal check; registered accessors keep their existing path. Assisted-by: Claude Code:claude-opus-5-5
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1230 +/- ##
=======================================
Coverage 89.48% 89.48%
=======================================
Files 9 9
Lines 6666 6668 +2
=======================================
+ Hits 5965 5967 +2
Misses 701 701 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Description
rx.__getattribute__handles every public, non-rxname by checking disposal, then returning a getattr clone if the node is lazy, then resolving the node if it is dirty, and only after that checking whether the name is defined on the class. The resolve was only ever needed to build the list of attributes on the wrapped value, but because of the ordering a property or method defined on anrxsubclass forced a full compute of a dirty node just to be read,hasattr(node, name)computed too, and on a lazy node the class attribute was swapped for a deferred getattr clone.__setattr__never resolves, so reads and writes were asymmetric: a downstream subclass that applies N input masks through a property computes a cold node N times, and a typo'sKeyErroronly shows up after a compute.Names defined on
type(self)or any class in its MRO now return straight after the disposal check. Class attributes already took precedence over value attributes in the old code (name not in super().__dir__()), so the only behaviour change is that these reads no longer resolve and no longer turn into lazy clones. Notes on the edge cases:rx._accessors) are left out of the fast path and go through the existing code unchanged, so the predicate still runs against a resolvedcurrent. None are class attributes onrx, but a name registered as an accessor still wins over a class attribute of the same name, as before. Accessors already memoized in the instance__dict__are not class-defined and also keep their current path._-prefixed names were never checked and still aren't.rxthe only public class-defined names besidesrxare theregister_*classmethods, which nobody expects to proxy to the value.Tests in
TestSubclassAttributescover property, method, classmethod andhasattrreads on a dirty node (no upstream call), a lazy node returning the property value, the disposed-node error, accessor predicates still seeing the resolved value, and value attributes still proxying and resolving (rx('abc').upper(), attribute of an object, deferred method on a lazy node).pytest tests/testreactive.pypasses (598 tests) andpixi run test-unitreports 2057 passed.pixi run test-unitexits non-zero on both this branch andmainbecause of unraisable socket and event-loop__del__warnings raised after the session, andtests/testimports.py::test_no_blocklist_importsfails in a local conda env (dev3.14) onmaintoo, so neither failure comes from this change.AI Disclosure
Tool & Model: Claude Code + claude-opus-5-5
Usage: Claude Code read the method and its git history, wrote the change and the tests, ran the test suite, and drafted this description.
Checklist