Use dataclass instead of NamedTuple for serializing AssetCondition #21147
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.
Summary & Motivation
We're about to start serializing these things, so making a diving save to allow us to use the nicer dataclass API instead of NamedTuples.
In the process of doing this, I realized that we had a weird setup with a
children
property on the base AssetCondition class that didn't work when using dataclasses. Previously, using NamedTuples meant that the NamedTuple property management stuff would handle the case where you added an explicitchildren
field on the child class, but dataclasses don't work in the same way.Basically we want a few things:
This new system makes it so that AssetConditions that do have sub-conditions just store them in a field with a different name (currently we're just doing boolean expressions, so I've used "operand" / "operands"), and then implement an explicit "children" property on top of that field. AssetConditions without sub-conditions just use the default "children" implementation, which returns an empty list.
Overall, this setup works a lot nicer and simplifies the class definitions for all these subclasses.
How I Tested These Changes