-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set/mutate_parameter:Fix for >1 refs of same event
Before this patch it was dangerous to call 'set_parameter' or 'mutate_parameter' on a 'mutwo.core_events.ComplexEvent' which containes multiple references of the same event. It was dangerous, because set_parameter would could many times on the same event, which would lead to unexpected results. For instance: >>> simple_event = core_events.SimpleEvent(2) >>> s = core_events.SequentialEvent([simple_event, simple_event]) >>> s.set_parameter('duration', lambda old_duration: old_duration * 2) >>> s[0].duration 8 So instead of the expected return value '4' (which would be the old_duration 2 multiplied by 2) we get 8, because 'set_parameter' has been called twice since there are two references of the same event 'simple_event'. After this patch the above code would return the expected 4. This patch changes the API of inheriting from the abstract base class 'mutwo.core_events.abc.Event'. Instead of overriding the abstract methods "set_parameter" and "mutate_parameter", users need to override the methods "_set_parameter" and "_mutate_parameter". Because no outside library currently depends on this ABC API detail (and 99.999% of all time users will inherit from SimpleEvent or SequentialEvent or SimultaneousEvent) this change is not considered to break the major version of mutwo, but only to be a bug fix actually. --- This patch fixes issue #23. Additional context can be found there.
- Loading branch information
levinericzimmermann
committed
Nov 12, 2022
1 parent
5f028bc
commit 8c17c27
Showing
2 changed files
with
157 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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