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

Conversation

dhdavvie
Copy link
Contributor

@dhdavvie dhdavvie commented Jan 15, 2019

UUID objects don't currently allow for weak referencing with their new slots implementation. This would cause regressions if people using weak referencing on these objects were to upgrade Python version. Also added a basic regression test that fails without the change implemented.

This is my first PR to cpython, so please let me know if there is something I forgot to do!

https://bugs.python.org/issue35701

@@ -657,6 +658,10 @@ 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

Lib/uuid.py Outdated
@@ -118,7 +118,7 @@ class UUID:
uuid_generate_time_safe(3).
"""

__slots__ = ('int', 'is_safe')
__slots__ = 'int', 'is_safe', '__weakref__'
Copy link
Member

Choose a reason for hiding this comment

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

please keep parenthesis, IMHO they help for readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, have added these.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

Ah, it now looks better. Second round of review.

def test_uuid_weakref(self):
strong = self.uuid.uuid4()
weak = weakref.ref(strong)
assert strong is weak()
Copy link
Member

Choose a reason for hiding this comment

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

Please replace assert with self.assertIs().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course, may I ask why?

Copy link
Member

Choose a reason for hiding this comment

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

"assert" is removed when running python -O. Moreover, assertIs() provides better error messages on failure (render the two variables).

@@ -0,0 +1 @@
Re-enable the ability to weakly reference a UUID object.
Copy link
Member

Choose a reason for hiding this comment

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

It seems like https://bugs.python.org/issue30977 was never released, the change was only made in the master branch. So no user got the issue with a public release. If I'm right, the NEWS entry is useless.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe you are correct, I was a bit unsure if I needed to then mention it. Should I drop the commit and force push? It seems like the bot detects when there is no news blurb and throws an error, is this optional then?

Copy link
Member

Choose a reason for hiding this comment

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

Remove the NEWS entry. I will add the "skip news" label, don't worry.

@@ -657,6 +658,11 @@ def testIssue8621(self):

self.assertNotEqual(parent_value, child_value)

# bpo-35701: check that weak referencing to a UUID object can be created
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: usually we put the comment inside the function, not outside ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no worries, I'll move it inside. Usually for something like this I would fixup the commit and force push, is that ok to do here or is the convention to use separate commits for the entire process?

Copy link
Member

Choose a reason for hiding this comment

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

I prefer to have multiple commits, they will be squashed into a single commit as the end anyway.

Copy link
Member

Choose a reason for hiding this comment

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

Different commits are simpler to review.

@vstinner vstinner merged commit f1d8e7c into python:master Jan 17, 2019
@vstinner
Copy link
Member

Thanks! I merged your PR.

@dhdavvie
Copy link
Contributor Author

Thank you! There were some things regarding comments made in the "What's New" section brought up in the bpo issue, I will open a new PR for that once an agreement has been reached

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants