Skip to content
Closed
Changes from 1 commit
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
Next Next commit
gh-145056: Let dict specific tests accept frozendict as well
  • Loading branch information
rhettinger committed Feb 21, 2026
commit f27f128ab9ddcecee092e4f9ff61b9f95b2d505d
8 changes: 4 additions & 4 deletions Lib/collections/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Contributor Author

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).

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)
Expand Down Expand Up @@ -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)):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Any tests for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, I didn't see where the dict version was tested so left this alone.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Very bad. We need to add tests with dict first.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

#145145 will add new tests. Now there will be a place for new frozendict tests.

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

Expand Down
Loading