-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use dataclass instead of NamedTuple for serializing AssetCondition (#…
…21147) ## 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 explicit `children` field on the child class, but dataclasses don't work in the same way. Basically we want a few things: - To have a property on all AssetConditions that lists all sub-conditions (if any) - To not have to explicitly store a set of sub-conditions in serialized form if there aren't any (mostly a dev ergonomics thing, it's a pain to add a guaranteed-to-be-empty "children" property to all child classes) - To make it easy to set invariants that certain AssetConditions will only have a single child, etc. 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
- Loading branch information
1 parent
378c41d
commit 454f16f
Showing
3 changed files
with
39 additions
and
37 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
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