From 067f146b42fc28aeffff567e841e0cb98817fee7 Mon Sep 17 00:00:00 2001 From: wouter bolsterlee Date: Wed, 19 Jul 2017 17:28:43 +0200 Subject: [PATCH] define uuid.UUID.__slots__ to save memory --- Lib/uuid.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Lib/uuid.py b/Lib/uuid.py index d4259ae0b3bd67..dfac31112aec9b 100644 --- a/Lib/uuid.py +++ b/Lib/uuid.py @@ -117,6 +117,8 @@ class UUID: uuid_generate_time_safe(3). """ + __slots__ = ('int', 'is_safe') + def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None, int=None, version=None, *, is_safe=SafeUUID.unknown): @@ -200,8 +202,8 @@ def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None, # Set the version number. int &= ~(0xf000 << 64) int |= version << 76 - self.__dict__['int'] = int - self.__dict__['is_safe'] = is_safe + super().__setattr__('int', int) + super().__setattr__('is_safe', is_safe) def __eq__(self, other): if isinstance(other, UUID):