Skip to content

bpo-35701: Added '__weakref__' to UUID __slots__ list to prevent regression. #11570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/test/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import shutil
import subprocess
import sys
import weakref
from unittest import mock

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

self.assertNotEqual(parent_value, child_value)

def test_uuid_weakref(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a short comment mentioning bpo-35701. Example: "bpo-35701: check that a weak reference to a UUID object can be created".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, pushed the change

# 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
Expand Down
2 changes: 1 addition & 1 deletion Lib/uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down