summaryrefslogtreecommitdiff
path: root/Lib/uuid.py
diff options
context:
space:
mode:
authorTal Einat <taleinat+github@gmail.com>2018-09-10 18:47:29 +0300
committerGitHub <noreply@github.com>2018-09-10 18:47:29 +0300
commitd53f1cabe8837697df4acb70c9c6537461b5eeda (patch)
treef6998cc9ac6a95c57d15ac0f28bca3c2372066f9 /Lib/uuid.py
parente9119a5de67d5525f3be957fda239143453513bd (diff)
downloadcpython-git-d53f1cabe8837697df4acb70c9c6537461b5eeda.tar.gz
[3.7] bpo-34621: fix uuid.UUID (un)pickling compatbility with older Python versions (<3.7) (GH-9133)
Diffstat (limited to 'Lib/uuid.py')
-rw-r--r--Lib/uuid.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/uuid.py b/Lib/uuid.py
index 66383218e7..26faa1accd 100644
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -204,6 +204,23 @@ class UUID:
self.__dict__['int'] = int
self.__dict__['is_safe'] = is_safe
+ def __getstate__(self):
+ state = self.__dict__
+ if self.is_safe != SafeUUID.unknown:
+ # is_safe is a SafeUUID instance. Return just its value, so that
+ # it can be un-pickled in older Python versions without SafeUUID.
+ state = state.copy()
+ state['is_safe'] = self.is_safe.value
+ return state
+
+ def __setstate__(self, state):
+ self.__dict__.update(state)
+ # is_safe was added in 3.7; it is also omitted when it is "unknown"
+ self.__dict__['is_safe'] = (
+ SafeUUID(state['is_safe'])
+ if 'is_safe' in state else SafeUUID.unknown
+ )
+
def __eq__(self, other):
if isinstance(other, UUID):
return self.int == other.int