]> granicus.if.org Git - python/commitdiff
bpo-35701: Added __weakref__ slot to uuid.UUID (GH-11570)
authorDavid H <dhdavvie@gmail.com>
Thu, 17 Jan 2019 12:16:51 +0000 (13:16 +0100)
committerVictor Stinner <vstinner@redhat.com>
Thu, 17 Jan 2019 12:16:51 +0000 (13:16 +0100)
Added test for weakreferencing a uuid.UUID object.

Lib/test/test_uuid.py
Lib/uuid.py

index 757bf3cc41939da10b658da5ec4f900c5baeab7c..992ef0cbf8048cef5945942a20ea1d25422a6ba7 100644 (file)
@@ -9,6 +9,7 @@ import pickle
 import shutil
 import subprocess
 import sys
+import weakref
 from unittest import mock
 
 py_uuid = support.import_fresh_module('uuid', blocked=['_uuid'])
@@ -657,6 +658,11 @@ class BaseTestUUID:
 
             self.assertNotEqual(parent_value, child_value)
 
+    def test_uuid_weakref(self):
+        # bpo-35701: check that weak referencing to a UUID object can be created
+        strong = self.uuid.uuid4()
+        weak = weakref.ref(strong)
+        self.assertIs(strong, weak())
 
 class TestUUIDWithoutExtModule(BaseTestUUID, unittest.TestCase):
     uuid = py_uuid
index 4468d4a6c1f9e798ab4305af64e36daf14b41abc..ddc63ccd082c0b18afc161bf46711aff0f1f7e62 100644 (file)
@@ -118,7 +118,7 @@ class UUID:
                     uuid_generate_time_safe(3).
     """
 
-    __slots__ = ('int', 'is_safe')
+    __slots__ = ('int', 'is_safe', '__weakref__')
 
     def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None,
                        int=None, version=None,