-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-36144: Add union operators to WeakValueDictionary584 #19127
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
bpo-36144: Add union operators to WeakValueDictionary584 #19127
Conversation
Updated weakref.py Added tests Updated docs Updated news
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, you might get 3 PRs merged in one day!
Looks great, a couple of comments though:
Lib/test/test_weakref.py
Outdated
wvd1 = weakref.WeakValueDictionary({1 : a}) | ||
wvd2 = weakref.WeakValueDictionary({1 : b, 2 : a}) | ||
wvd3 = wvd1.copy() | ||
d1 = {1 : c, 3 : b} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No space before :
, ever!
wvd1 = weakref.WeakValueDictionary({1 : a}) | |
wvd2 = weakref.WeakValueDictionary({1 : b, 2 : a}) | |
wvd3 = wvd1.copy() | |
d1 = {1 : c, 3 : b} | |
wvd1 = weakref.WeakValueDictionary({1: a}) | |
wvd2 = weakref.WeakValueDictionary({1: b, 2: a}) | |
wvd3 = wvd1.copy() | |
d1 = {1: c, 3: b} |
Lib/test/test_weakref.py
Outdated
wvd2 = weakref.WeakValueDictionary({1 : b, 2 : a}) | ||
wvd3 = wvd1.copy() | ||
d1 = {1 : c, 3 : b} | ||
pairs = [(5, c), (5, b)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an interesting test case, but I just want to verify that you intended to use the same key twice here.
You didn't mean something like this, which results in a mapping of length 2?
pairs = [(5, c), (5, b)] | |
pairs = [(5, c), (6, b)] |
Lib/test/test_weakref.py
Outdated
self.assertNotIn(2, tmp1.keys()) | ||
self.assertNotIn(2, tmp2.keys()) | ||
self.assertNotIn(1, tmp3.keys()) | ||
self.assertNotIn(1, tmp4.keys()) |
There was a p 8000 roblem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need the keys()
calls here:
self.assertNotIn(2, tmp1.keys()) | |
self.assertNotIn(2, tmp2.keys()) | |
self.assertNotIn(1, tmp3.keys()) | |
self.assertNotIn(1, tmp4.keys()) | |
self.assertNotIn(2, tmp1) | |
self.assertNotIn(2, tmp2) | |
self.assertNotIn(1, tmp3) | |
self.assertNotIn(1, tmp4) |
Doc/library/weakref.rst
Outdated
.. versionchanged:: 3.9 | ||
Added support for ``|`` and ``|=`` operators, specified in :pep:`584`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is better moved up to line 174, just after the ..note::
(and at the same indentation level).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be more like line 200, because I believe line 174 is under WeakKeyDictionary
rather than WeakValueDictionary
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, nice catch.
Fixed styling and readibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @curtisbucher. I agree with the inclusion of a versionadded
for support of the union operators on dictionaries, it's a substantial new feature.
Grammar Co-Authored-By: Kyle Stanley <aeros167@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup.
@gvanrossum: Please replace |
Oops, screwed up the commit title. Oh well, we'll live. Thanks again @curtisbucher and @brandtbucher ! |
|
Buildbot failure looks unrelated. |
Agreed |
@brandtbucher
https://bugs.python.org/issue36144