diff options
| author | Lex Neva <lexelby@users.noreply.github.com> | 2023-02-20 15:27:15 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-20 15:27:15 -0500 |
| commit | 8b98083ac723e4145a7c41483f7dda10f722566f (patch) | |
| tree | 9a058b6aa3c907d3da12d3efdfbc115ef1b4eff4 /lib/stitch_plan/stitch_group.py | |
| parent | 43ec2db4516545744051d5762728f287cc19acf6 (diff) | |
| parent | aa65a2bf3fb747dc89e2d905f1fc45b269b5cab4 (diff) | |
Merge pull request #1732 from inkstitch/lexelby/cache-stitch-plan
stitch plan caching
Diffstat (limited to 'lib/stitch_plan/stitch_group.py')
| -rw-r--r-- | lib/stitch_plan/stitch_group.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/stitch_plan/stitch_group.py b/lib/stitch_plan/stitch_group.py index 6dbeb9e5..717bb617 100644 --- a/lib/stitch_plan/stitch_group.py +++ b/lib/stitch_plan/stitch_group.py @@ -19,6 +19,11 @@ class StitchGroup: def __init__(self, color=None, stitches=None, trim_after=False, stop_after=False, tie_modus=0, force_lock_stitches=False, stitch_as_is=False, tags=None): + # DANGER: if you add new attributes, you MUST also set their default + # values in __new__() below. Otherwise, cached stitch plans can be + # loaded and create objects without those properties defined, because + # unpickling does not call __init__()! + self.color = color self.trim_after = trim_after self.stop_after = stop_after @@ -33,6 +38,14 @@ class StitchGroup: if tags: self.add_tags(tags) + def __new__(cls, *args, **kwargs): + instance = super().__new__(cls) + + # Set default values for any new attributes here (see note in __init__() above) + # instance.foo = None + + return instance + def __add__(self, other): if isinstance(other, StitchGroup): return StitchGroup(self.color, self.stitches + other.stitches) |
