Skip to content

Commit f1d8e7c

Browse files
dhdavvievstinner
authored andcommitted
bpo-35701: Added __weakref__ slot to uuid.UUID (GH-11570)
Added test for weakreferencing a uuid.UUID object.
1 parent 89669ff commit f1d8e7c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Lib/test/test_uuid.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import shutil
1010
import subprocess
1111
import sys
12+
import weakref
1213
from unittest import mock
1314

1415
py_uuid = support.import_fresh_module('uuid', blocked=['_uuid'])
@@ -657,6 +658,11 @@ def testIssue8621(self):
657658

658659
self.assertNotEqual(parent_value, child_value)
659660

661+
def test_uuid_weakref(self):
662+
# bpo-35701: check that weak referencing to a UUID object can be created
663+
strong = self.uuid.uuid4()
664+
weak = weakref.ref(strong)
665+
self.assertIs(strong, weak())
660666

661667
class TestUUIDWithoutExtModule(BaseTestUUID, unittest.TestCase):
662668
uuid = py_uuid

Lib/uuid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class UUID:
118118
uuid_generate_time_safe(3).
119119
"""
120120

121-
__slots__ = ('int', 'is_safe')
121+
__slots__ = ('int', 'is_safe', '__weakref__')
122122

123123
def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None,
124124
int=None, version=None,

0 commit comments

Comments
 (0)