-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
gh-145056: Let dict specific tests accept frozendict as well #145060
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -328,14 +328,14 @@ def __ior__(self, other): | |
| return self | ||
|
|
||
| def __or__(self, other): | ||
| if not isinstance(other, dict): | ||
| if not isinstance(other, (dict, frozendict)): | ||
| return NotImplemented | ||
| new = self.__class__(self) | ||
| new.update(other) | ||
| return new | ||
|
|
||
| def __ror__(self, other): | ||
| if not isinstance(other, dict): | ||
| if not isinstance(other, (dict, frozendict)): | ||
| return NotImplemented | ||
| new = self.__class__(other) | ||
| new.update(self) | ||
|
|
@@ -1221,14 +1221,14 @@ def __repr__(self): | |
| def __or__(self, other): | ||
| if isinstance(other, UserDict): | ||
| return self.__class__(self.data | other.data) | ||
| if isinstance(other, dict): | ||
| if isinstance(other, (dict, frozendict)): | ||
|
Member
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. Any tests for this?
Contributor
Author
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. No, I didn't see where the
Member
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. Very bad. We need to add tests with
Member
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. Well, let's leave this. There are many other missing tests for UserDict and UserList. I am working on this. |
||
| return self.__class__(self.data | other) | ||
| return NotImplemented | ||
|
|
||
| def __ror__(self, other): | ||
| if isinstance(other, UserDict): | ||
| return self.__class__(other.data | self.data) | ||
| if isinstance(other, dict): | ||
| if isinstance(other, (dict, frozendict)): | ||
| return self.__class__(other | self.data) | ||
| return NotImplemented | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -698,6 +698,7 @@ def test_merge_operator(self): | |
| d |= list(b.items()) | ||
| expected = OrderedDict({0: 0, 1: 1, 2: 2, 3: 3}) | ||
| self.assertEqual(a | dict(b), expected) | ||
| self.assertEqual(a | frozendict(b), expected) | ||
|
Member
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. Should not the type of the result to be tested too?
Contributor
Author
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. The existing test didn't check result type. I don't want to feature creep this edit. Reviewing and expanding the existing test strategies can be a task for another day.
Member
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. The new tests are passed with unmodified code. Therefore they are not correct tests for this change. |
||
| self.assertEqual(a | b, expected) | ||
| self.assertEqual(c, expected) | ||
| self.assertEqual(d, expected) | ||
|
|
@@ -706,6 +707,7 @@ def test_merge_operator(self): | |
| c |= a | ||
| expected = OrderedDict({1: 1, 2: 1, 3: 3, 0: 0}) | ||
| self.assertEqual(dict(b) | a, expected) | ||
| self.assertEqual(frozendict(b) | a, expected) | ||
| self.assertEqual(b | a, expected) | ||
| self.assertEqual(c, expected) | ||
|
|
||
|
|
||
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.
What about the C implementation?
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.
The C version already supported any mapping input, that is how the tests passed. But I will update the fast path to use
PyAnyDict_CheckExact(arg).