diff options
| author | Lex Neva <github.com@lexneva.name> | 2022-08-04 21:17:41 -0400 |
|---|---|---|
| committer | Lex Neva <github.com@lexneva.name> | 2023-02-18 22:34:47 -0500 |
| commit | 2865f4161e4b2e8dc63177ef60a83820ea4f761d (patch) | |
| tree | 6fb58104c7d6e51c56ec4c673f0c835f95c10ee3 /lib/stitch_plan/stitch.py | |
| parent | 98bc2e2ff9c843a64c3db355290ed541e6708312 (diff) | |
consistent cache key for Stitch objects
Diffstat (limited to 'lib/stitch_plan/stitch.py')
| -rw-r--r-- | lib/stitch_plan/stitch.py | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/lib/stitch_plan/stitch.py b/lib/stitch_plan/stitch.py index 67a0fd64..c1553ce5 100644 --- a/lib/stitch_plan/stitch.py +++ b/lib/stitch_plan/stitch.py @@ -55,16 +55,17 @@ class Stitch(Point): return instance def __repr__(self): - return "Stitch(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.x, - self.y, - self.color, - "JUMP" if self.jump else " ", - "TRIM" if self.trim else " ", - "STOP" if self.stop else " ", - "TIE MODUS" if self.tie_modus else " ", - "FORCE LOCK STITCHES" if self.force_lock_stitches else " ", - "NO TIES" if self.no_ties else " ", - "COLOR CHANGE" if self.color_change else " ") + return "Stitch(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" % (self.x, + self.y, + self.color, + self.tags, + "JUMP" if self.jump else " ", + "TRIM" if self.trim else " ", + "STOP" if self.stop else " ", + self.tie_modus, + "FORCE LOCK STITCHES" if self.force_lock_stitches else " ", + "NO TIES" if self.no_ties else " ", + "COLOR CHANGE" if self.color_change else " ") def _set(self, attribute, value, base_stitch): # Set an attribute. If the caller passed a Stitch object, use its value, unless @@ -104,3 +105,12 @@ class Stitch(Point): attributes = dict(vars(self)) attributes['tags'] = list(attributes['tags']) return attributes + + def __getstate__(self): + # This is used by pickle. We want to sort the tag list so that the + # pickled representation is stable, since it's used to generate cache + # keys. + state = self.__json__() + state['tags'].sort() + + return state |
