[3.7] bpo-34621: backwards-compatible pickle UUID with is_safe=unknow… · python/cpython@a2ea944 (original) (raw)

Original file line number Diff line number Diff line change
@@ -205,12 +205,14 @@ def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None,
205 205 self.__dict__['is_safe'] = is_safe
206 206
207 207 def __getstate__(self):
208 -state = self.__dict__
208 +state = self.__dict__.copy()
209 209 if self.is_safe != SafeUUID.unknown:
210 210 # is_safe is a SafeUUID instance. Return just its value, so that
211 211 # it can be un-pickled in older Python versions without SafeUUID.
212 -state = state.copy()
213 212 state['is_safe'] = self.is_safe.value
213 +else:
214 +# omit is_safe when it is "unknown"
215 +del state['is_safe']
214 216 return state
215 217
216 218 def __setstate__(self, state):