summaryrefslogtreecommitdiffstats
path: root/Lib/uuid.py
diff options
context:
space:
mode:
authorTal Einat <taleinat+github@gmail.com>2018-09-10 13:11:04 (GMT)
committerGitHub <noreply@github.com>2018-09-10 13:11:04 (GMT)
commit54752533b2ed1c898ffe5ec2e795c6910ee46a39 (patch)
tree02d254c2e1ed9865fe2c05086ba7dcb11d2b750d /Lib/uuid.py
parent1f36bf6077d93cb43fd84bea4a8a625fa772d1fa (diff)
downloadcpython-54752533b2ed1c898ffe5ec2e795c6910ee46a39.zip
cpython-54752533b2ed1c898ffe5ec2e795c6910ee46a39.tar.gz
cpython-54752533b2ed1c898ffe5ec2e795c6910ee46a39.tar.bz2
bpo-30977: rework code changes according to post-merge code review (GH-9106)
also mention the change and its consequences in What's New
Diffstat (limited to 'Lib/uuid.py')
-rw-r--r--Lib/uuid.py27
1 files changed, 10 insertions, 17 deletions
diff --git a/Lib/uuid.py b/Lib/uuid.py
index 5153882..073ca71 100644
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -207,26 +207,19 @@ class UUID:
object.__setattr__(self, 'is_safe', is_safe)
def __getstate__(self):
- d = {attr: getattr(self, attr) for attr in self.__slots__}
- # is_safe is a SafeUUID instance. Return just its value, so that
- # it can be unpickled in older Python versions without SafeUUID.
- d['is_safe'] = d['is_safe'].value
+ d = {'int': self.int}
+ 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.
+ d['is_safe'] = self.is_safe.value
return d
def __setstate__(self, state):
- # is_safe was added in 3.7
- state.setdefault('is_safe', SafeUUID.unknown.value)
-
- for attr in self.__slots__:
- value = state[attr]
-
- # for is_safe, restore the SafeUUID from the stored value
- if attr == 'is_safe':
- try:
- value = SafeUUID(value)
- except ValueError:
- value = SafeUUID.unknown
- object.__setattr__(self, attr, value)
+ object.__setattr__(self, 'int', state['int'])
+ # is_safe was added in 3.7; it is also omitted when it is "unknown"
+ object.__setattr__(self, 'is_safe',
+ SafeUUID(state['is_safe'])
+ if 'is_safe' in state else SafeUUID.unknown)
def __eq__(self, other):
if isinstance(other, UUID):