-
Notifications
You must be signed in to change notification settings - Fork 2
Fix dependent parameter division expressions triggering infinite recursion #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull request does not contain a valid label. Please add one of the following labels: ['[scope] bug', '[scope] enhancement', '[scope] documentation', '[scope] significant', '[scope] maintenance']
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #191 +/- ##
=======================================
Coverage 80.80% 80.80%
=======================================
Files 52 52
Lines 4261 4256 -5
Branches 739 739
=======================================
- Hits 3443 3439 -4
+ Misses 633 632 -1
Partials 185 185
Flags with carried forward coverage won't be shown. Click here to find out more.
|
…expressions Remove unnecessary value restoration lines in __truediv__ and __rtruediv__ methods that triggered observer notifications during expression evaluation, causing infinite recursion when dependent parameters used division expressions. Fixes the issue where "a / b" expressions would fail with AttributeError while "1/b * a" expressions worked correctly. Co-authored-by: rozyczko <8266281+rozyczko@users.noreply.github.com>
rozyczko
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good solution.
| raise ZeroDivisionError('Cannot divide by zero') | ||
| new_value = self.full_value / other | ||
| elif type(other) is DescriptorNumber: | ||
| original_other = other.value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd actually question whether restoration is needed at all. Reading .value shouldn't modify it: these are pure read operations followed by arithmetic. The only scenario where restoration would matter is if the getter has side effects that modify state, or some intermediate step in the calculation mutates the operand. This is highly unlikely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could swear this restoration was there for a reason, but I can't for the love of me figure out what that reason was . . .
But I guess we have unit tests and they don't fail after this change, so it must be fine? Right????
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DON'T QUESTION THE AI OVERLORDS
…ion_order Updated the regression test link for division expression order.
|
This probably should be reparented to |
Yeah, I don't think it is urgently required, @henrikjacobsenfys? |
Dependent parameter expressions like
"jump_length / angstrom"fail withAttributeError: 'NoneType' object has no attribute 'value'while mathematically equivalent expressions like"1/angstrom * jump_length"work correctly.Root Cause
The
__truediv__and__rtruediv__methods in bothParameterandDescriptorNumberhad unnecessary lines restoring operand values after reading them:Since the value setter has
@notify_observers, this triggered_update()on dependent parameters mid-evaluation, causing infinite recursion.Changes
other.value = other_valuefrom__truediv__andself.value = original_selffrom__rtruediv__other.value = original_otherfrom__truediv__and clean up unused variableOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.