Repository navigation
Honor fallback_value on Observable - #4189
Conversation
Observable accepted fallback_value but never used it: reading before the first assignment raised AttributeError, and the first CHANGED signal reported old=None. Observable now returns its fallback value when read before assignment (also from computed properties) and reports it as the old value of the first assignment, so assigning a value equal to the fallback emits nothing. Without a fallback value the behavior is unchanged: reading before assignment raises AttributeError and the first old value is None. A sentinel distinguishes "no fallback" from a fallback of None. BaseObservable.__set__ had old and new swapped and never stored the value. All subclasses override it, so it now raises NotImplementedError. Adds tests for both cases with and without a fallback value, and for BaseObservable.__set__. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RbrUQUQAArrpH7rYQFt6KW
|
Thanks for the fallback regression tests, @quaquel. The diff also replaces Please split that setter change and its test into a separate PR, or drop them here, so this PR addresses one problem. Automated note by an AI model; it can be wrong, and maintainers make the decisions. About this bot. |
|
I indeed collapse 2 fixes into 1 PR, but they touch the same part of the code and are at least somewhat related, so I favor proceeding with this as is. Also, with close to 50 PRs open continuously, I am hesitant to create even more noise. |
EwoutH
left a comment
There was a problem hiding this comment.
Fix and tests look good, and the tram example (Observable(fallback_value=...)) finally gets what it asks for. Tests pass locally.
One thing to keep in mind: #4190 documents the current behaviour in the Observable docstring ("reading an Observable before it has been assigned raises AttributeError", "for the first assignment, old is None"). Whichever of the two lands second should update those lines to mention fallback_value.
Observable accepted
fallback_valuebut never used it. Reading before the first assignment raised AttributeError, and the first CHANGED signal reported old=None.Observable now returns its fallback value when read before assignment (also from computed properties) and reports it as the old value of the first assignment, so assigning a value equal to the fallback emits nothing. Without a fallback value, the behavior is unchanged: reading before assignment raises AttributeError and the first old value is None. A sentinel distinguishes "no fallback" from a fallback of None.
BaseObservable.__set__hadoldandnewswapped and never stored the value. All subclasses override it, so it now raisesNotImplementedError.Adds tests for both cases with and without a fallback value, and for BaseObservable.set.