Skip to content

Commit

Permalink
Implement reduce() in terms of append().
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxColoring committed Nov 25, 2024
1 parent 463f34f commit d6813ae
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions api/src/opentrons/protocol_engine/state/update_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,19 +319,10 @@ def reduce(cls: typing.Type[Self], *args: Self) -> Self:
State updates that are later in the parameter list are preferred to those that are earlier;
NO_CHANGE is ignored.
"""
fields = dataclasses.fields(cls)
changes_dicts = [
{
field.name: update.__dict__[field.name]
for field in fields
if update.__dict__[field.name] != NO_CHANGE
}
for update in args
]
changes = {}
for changes_dict in changes_dicts:
changes.update(changes_dict)
return cls(**changes)
accumulator = cls()
for arg in args:
accumulator.append(arg)
return accumulator

# These convenience functions let the caller avoid the boilerplate of constructing a
# complicated dataclass tree.
Expand Down

0 comments on commit d6813ae

Please sign in to comment.