-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Changes from 1 commit
bc4e7e7
cef9fd2
3829134
f1b6195
ea5465a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1610,19 +1610,41 @@ def test_weak_valued_dict_update(self): | |||||||||||||||||
self.assertEqual(d[kw], o) | ||||||||||||||||||
|
||||||||||||||||||
def test_weak_valued_union_operators(self): | ||||||||||||||||||
class C: pass | ||||||||||||||||||
c1 = C() | ||||||||||||||||||
c2 = C() | ||||||||||||||||||
c3 = C() | ||||||||||||||||||
a = C() | ||||||||||||||||||
b = C() | ||||||||||||||||||
c = C() | ||||||||||||||||||
wvd1 = weakref.WeakValueDictionary({1 : a}) | ||||||||||||||||||
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 commentThe 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?
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
tmp1 = wvd1 | wvd2 # Between two WeakValueDictionaries | ||||||||||||||||||
self.assertEqual(dict(tmp1), dict(wvd1) | dict(wvd2)) | ||||||||||||||||||
self.assertIs(type(tmp1), weakref.WeakValueDictionary) | ||||||||||||||||||
wvd1 |= wvd2 | ||||||||||||||||||
self.assertEqual(wvd1, tmp1) | ||||||||||||||||||
|
||||||||||||||||||
wvd1 = weakref.WeakValueDictionary({'1' : c1, '2': c2}) | ||||||||||||||||||
wvd2 = weakref.WeakValueDictionary({'1': c3, '4': c1}) | ||||||||||||||||||
tmp2 = wvd2 | d1 # Between WeakValueDictionary and mapping | ||||||||||||||||||
self.assertEqual(dict(tmp2), dict(wvd2) | d1) | ||||||||||||||||||
self.assertIs(type(tmp2), weakref.WeakValueDictionary) | ||||||||||||||||||
wvd2 |= d1 | ||||||||||||||||||
self.assertEqual(wvd2, tmp2) | ||||||||||||||||||
|
||||||||||||||||||
wvd3 = wvd1 | wvd2 | ||||||||||||||||||
self.assertEqual(dict(wvd3), dict(wvd1) | dict(wvd2)) | ||||||||||||||||||
tmp3 = wvd3.copy() # Between WeakValueDictionary and iterable key, value | ||||||||||||||||||
tmp3 |= pairs | ||||||||||||||||||
self.assertEqual(dict(tmp3), dict(wvd3) | dict(pairs)) | ||||||||||||||||||
self.assertIs(type(tmp3), weakref.WeakValueDictionary) | ||||||||||||||||||
|
||||||||||||||||||
wvd1 |= wvd2 | ||||||||||||||||||
self.assertEqual(wvd1, wvd3) | ||||||||||||||||||
tmp4 = d1 | wvd3 # Testing .__ror__ | ||||||||||||||||||
self.assertEqual(dict(tmp4), d1 | dict(wvd3)) | ||||||||||||||||||
self.assertIs(type(tmp4), weakref.WeakValueDictionary) | ||||||||||||||||||
|
||||||||||||||||||
del a | ||||||||||||||||||
self.assertNotIn(2, tmp1.keys()) | ||||||||||||||||||
self.assertNotIn(2, tmp2.keys()) | ||||||||||||||||||
self.assertNotIn(1, tmp3.keys()) | ||||||||||||||||||
self.assertNotIn(1, tmp4.keys()) | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need the
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
def test_weak_keyed_dict_update(self): | ||||||||||||||||||
self.check_update(weakref.WeakKeyDictionary, | ||||||||||||||||||
|
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!